id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
42,799
package.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/package.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: package.lisp,v 1.22 2006/03/27 21:57:37 xach Exp $ (defpackage #:zpb-ttf (:use #:cl) (:export ;; font loader #:open-font-loader #:close-font-loader #:with-font-loader #:glyph-count #:name-entry-value #:find-name-entry #:value #:collection-font-count #:collection-font-index ;; font typographic #:italic-angle #:underline-thickness #:underline-position #:fixed-pitch-p #:units/em #:ascender #:descender #:line-gap ;; other font attributes #:postscript-name #:full-name #:family-name #:subfamily-name #:all-kerning-pairs #:glyph-exists-p #:index-glyph #:find-glyph ;; shared between font-loader and glyph #:bounding-box #:xmin #:ymin #:xmax #:ymax ;; control points #:x #:y #:on-curve-p ;; glyph contours #:contour-count #:contour #:contours #:do-contours #:explicit-contour-points #:do-contour-segments #:do-contour-segments* ;; glyph other #:code-point #:font-index ;; glyph typographic #:advance-width #:left-side-bearing #:right-side-bearing #:kerning-offset #:string-bounding-box))
2,523
Common Lisp
.lisp
85
26.670588
70
0.706486
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
157ef8619206fdadf22b9ae383f80e18302bf4fd4da88a4b559bbc1287b22965
42,799
[ -1 ]
42,800
util.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/util.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Utility functions, mostly for reading data out of the input-stream ;;; of a font-loader. ;;; ;;; $Id: util.lisp,v 1.9 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) ;;; Reading compound MSB values from an '(unsigned-byte 8) stream (defun read-uint32 (stream) (loop repeat 4 for value = (read-byte stream) then (logior (ash value 8) (read-byte stream)) finally (return value))) (defun read-uint16 (stream) (loop repeat 2 for value = (read-byte stream) then (logior (ash value 8) (read-byte stream)) finally (return value))) (defun read-uint8 (stream) (read-byte stream)) (defun read-int8 (stream) (let ((result (read-byte stream))) (if (logbitp 7 result) (1- (- (logandc2 #xFF result))) result))) (defun read-int16 (stream) (let ((result (read-uint16 stream))) (if (logbitp 15 result) (1- (- (logandc2 #xFFFF result))) result))) (defun read-fixed (stream) (read-uint32 stream)) (defun read-fword (stream) (read-int16 stream)) (defun read-fixed2.14 (stream) (let ((value (read-uint16 stream))) (let ((integer (ash value -14)) (fraction (logand #x3FFF value))) (when (logbitp 1 integer) (setf integer (1- (- (logandc2 #b11 integer))))) (+ integer (float (/ fraction #x3FFF)))))) (defun read-pstring (stream) "Read a Pascal-style length-prefixed string." (let* ((length (read-uint8 stream)) (buf (make-array length :element-type '(unsigned-byte 8))) (string (make-string length))) (read-sequence buf stream) ;; The following could be (map 'string #'code-char buf), but that ;; form benchmarked poorly (dotimes (i length string) (setf (schar string i) (code-char (aref buf i)))))) (defun advance-file-position (stream n) "Move the file position of STREAM ahead by N bytes." (let ((pos (file-position stream))) (file-position stream (+ pos n)))) (defun bounded-aref (vector index) "Some TrueType data vectors are truncated, and any references beyond the end of the vector should be treated as a reference to the last element in the vector." (aref vector (min (1- (length vector)) index))) (defun (setf bounded-aref) (new-value vector index) (setf (aref vector (min (1- (length vector)) index)) new-value))
3,682
Common Lisp
.lisp
86
39.337209
70
0.696454
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5d3e8d9306522c18357b84d97b9c9d4e8a56e7fd23cbb34053b9998f73df9ead
42,800
[ -1 ]
42,801
font-loader.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/font-loader.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; The font-loader object, which is the primary interface for ;;; getting glyph and metrics info. ;;; ;;; $Id: font-loader.lisp,v 1.26 2006/03/23 22:21:40 xach Exp $ (in-package #:zpb-ttf) (defclass font-loader () ((tables :initform (make-hash-table) :reader tables) (input-stream :initarg :input-stream :accessor input-stream :documentation "The stream from which things are loaded.") (table-count :initarg :table-count :reader table-count) ;; from the 'head' table (units/em :accessor units/em) (bounding-box :accessor bounding-box) (loca-offset-format :accessor loca-offset-format) ;; from the 'loca' table (glyph-locations :accessor glyph-locations) ;; from the 'cmap' table (character-map :accessor character-map) (inverse-character-map :accessor inverse-character-map) ;; from the 'maxp' table (glyph-count :accessor glyph-count) ;; from the 'hhea' table (ascender :accessor ascender) (descender :accessor descender) (line-gap :accessor line-gap) ;; from the 'hmtx' table (advance-widths :accessor advance-widths) (left-side-bearings :accessor left-side-bearings) ;; from the 'kern' table (kerning-table :initform (make-hash-table) :accessor kerning-table) ;; from the 'name' table (name-entries :initform nil :accessor name-entries) ;; from the 'post' table (italic-angle :accessor italic-angle :initform 0) (fixed-pitch-p :accessor fixed-pitch-p :initform nil) (underline-position :accessor underline-position :initform 0) (underline-thickness :accessor underline-thickness :initform 0) (postscript-glyph-names :accessor postscript-glyph-names) ;; misc (glyph-cache :accessor glyph-cache) ;; # of fonts in collection, if loaded from a ttc file (collection-font-count :reader collection-font-count :initform nil :initarg :collection-font-cont) ;; index of font in collection, if loaded from a ttc file (collection-font-index :reader collection-font-index :initform nil :initarg :collection-font-index))) (defclass table-info () ((name :initarg :name :reader name) (offset :initarg :offset :reader offset) (size :initarg :size :reader size))) (defmethod print-object ((object table-info) stream) (print-unreadable-object (object stream :type t) (format stream "\"~A\"" (name object)))) ;;; tag integers to strings and back (defun number->tag (number) "Convert the 32-bit NUMBER to a string of four characters based on the CODE-CHAR of each octet in the number." (let ((tag (make-string 4))) (loop for i below 4 for offset from 24 downto 0 by 8 do (setf (schar tag i) (code-char (ldb (byte 8 offset) number)))) tag)) (defun tag->number (tag) "Convert the four-character string TAG to a 32-bit number based on the CHAR-CODE of each character." (declare (simple-string tag)) (loop for char across tag for offset from 24 downto 0 by 8 summing (ash (char-code char) offset))) ;;; Getting table info out of the loader (defmethod table-info ((tag string) (font-loader font-loader)) (gethash (tag->number tag) (tables font-loader))) (defmethod table-exists-p (tag font-loader) (nth-value 1 (table-info tag font-loader))) (defmethod table-position ((tag string) (font-loader font-loader)) "Return the byte position in the font-loader's stream for the table named by TAG." (let ((table-info (table-info tag font-loader))) (if table-info (offset table-info) (error "No such table -- ~A" tag)))) (defmethod table-size ((tag string) (font-loader font-loader)) (let ((table-info (table-info tag font-loader))) (if table-info (size table-info) (error "No such table -- ~A" tag)))) (defmethod seek-to-table ((tag string) (font-loader font-loader)) "Move FONT-LOADER's input stream to the start of the table named by TAG." (let ((table-info (table-info tag font-loader))) (if table-info (seek-to-table table-info font-loader) (error "No such table -- ~A" tag)))) (defmethod seek-to-table ((table table-info) (font-loader font-loader)) "Move FONT-LOADER's input stream to the start of TABLE." (file-position (input-stream font-loader) (offset table)))
5,654
Common Lisp
.lisp
122
42.434426
75
0.710918
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
acf084b3733265d2c1cbca6ad17433d73c4b3076da3d29752541c4af61605ab1
42,801
[ -1 ]
42,802
name.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/name.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the TrueType "name" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/name ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html ;;; ;;; $Id: name.lisp,v 1.8 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defvar *name-identifiers* #(:copyright-notice :font-family :font-subfamily :unique-subfamily :full-name :name-table-version :postscript-name :trademark-notice :manufacturer-name :designer :description :vendor-url :designer-url :license-description :licence-info-url :reserved :preferred-family :preferred-subfamily :compatible-full :sample-text)) (defvar *platform-identifiers* #(:unicode :macintosh :iso :microsoft :custom)) (defvar *unicode-encoding-ids* #(:unicode-1.0 :unicode-1.1 :iso-10646\:1993 :unicode>=2.0-bmp-only :unicode>=2.0-full-repertoire)) (defvar *microsoft-encoding-ids* #(:symbol :unicode :shiftjis :prc :big5 :wansung :johab :reserved :reserved :reserved :ucs-4)) (defvar *macintosh-encoding-ids* #(:roman :japanese :chinese-traditional :korean :arabic :hebrew :greek :russian :RSymbol :devanagari :gurmukhi :gujarati :oriya :bengali :tamil :telugu :kennada :malayam :sinhalese :burmese :khmer :thai :laotian :georgian :armenian :chinese-simplified :tibetan :mongolian :geez :slavic :vietnamese :sindhi :uninterpreted)) (defparameter *encoding-tables* (vector *unicode-encoding-ids* *macintosh-encoding-ids* nil *microsoft-encoding-ids* nil)) (defun encoding-id-name (platform-id encoding-id) (aref (aref *encoding-tables* platform-id) encoding-id)) (defun platform-id-name (platform-id) (aref *platform-identifiers* platform-id)) (defparameter *macroman-translation-table* #(#x00 #x00 #x01 #x01 #x02 #x02 #x03 #x03 #x04 #x04 #x05 #x05 #x06 #x06 #x07 #x07 #x08 #x08 #x09 #x09 #x0A #x0A #x0B #x0B #x0C #x0C #x0D #x0D #x0E #x0E #x0F #x0F #x10 #x10 #x11 #x11 #x12 #x12 #x13 #x13 #x14 #x14 #x15 #x15 #x16 #x16 #x17 #x17 #x18 #x18 #x19 #x19 #x1A #x1A #x1B #x1B #x1C #x1C #x1D #x1D #x1E #x1E #x1F #x1F #x20 #x20 #x21 #x21 #x22 #x22 #x23 #x23 #x24 #x24 #x25 #x25 #x26 #x26 #x27 #x27 #x28 #x28 #x29 #x29 #x2A #x2A #x2B #x2B #x2C #x2C #x2D #x2D #x2E #x2E #x2F #x2F #x30 #x30 #x31 #x31 #x32 #x32 #x33 #x33 #x34 #x34 #x35 #x35 #x36 #x36 #x37 #x37 #x38 #x38 #x39 #x39 #x3A #x3A #x3B #x3B #x3C #x3C #x3D #x3D #x3E #x3E #x3F #x3F #x40 #x40 #x41 #x41 #x42 #x42 #x43 #x43 #x44 #x44 #x45 #x45 #x46 #x46 #x47 #x47 #x48 #x48 #x49 #x49 #x4A #x4A #x4B #x4B #x4C #x4C #x4D #x4D #x4E #x4E #x4F #x4F #x50 #x50 #x51 #x51 #x52 #x52 #x53 #x53 #x54 #x54 #x55 #x55 #x56 #x56 #x57 #x57 #x58 #x58 #x59 #x59 #x5A #x5A #x5B #x5B #x5C #x5C #x5D #x5D #x5E #x5E #x5F #x5F #x60 #x60 #x61 #x61 #x62 #x62 #x63 #x63 #x64 #x64 #x65 #x65 #x66 #x66 #x67 #x67 #x68 #x68 #x69 #x69 #x6A #x6A #x6B #x6B #x6C #x6C #x6D #x6D #x6E #x6E #x6F #x6F #x70 #x70 #x71 #x71 #x72 #x72 #x73 #x73 #x74 #x74 #x75 #x75 #x76 #x76 #x77 #x77 #x78 #x78 #x79 #x79 #x7A #x7A #x7B #x7B #x7C #x7C #x7D #x7D #x7E #x7E #x7F #x7F #x80 #x00C4 #x81 #x00C5 #x82 #x00C7 #x83 #x00C9 #x84 #x00D1 #x85 #x00D6 #x86 #x00DC #x87 #x00E1 #x88 #x00E0 #x89 #x00E2 #x8A #x00E4 #x8B #x00E3 #x8C #x00E5 #x8D #x00E7 #x8E #x00E9 #x8F #x00E8 #x90 #x00EA #x91 #x00EB #x92 #x00ED #x93 #x00EC #x94 #x00EE #x95 #x00EF #x96 #x00F1 #x97 #x00F3 #x98 #x00F2 #x99 #x00F4 #x9A #x00F6 #x9B #x00F5 #x9C #x00FA #x9D #x00F9 #x9E #x00FB #x9F #x00FC #xA0 #x2020 #xA1 #x00B0 #xA2 #x00A2 #xA3 #x00A3 #xA4 #x00A7 #xA5 #x2022 #xA6 #x00B6 #xA7 #x00DF #xA8 #x00AE #xA9 #x00A9 #xAA #x2122 #xAB #x00B4 #xAC #x00A8 #xAD #x2260 #xAE #x00C6 #xAF #x00D8 #xB0 #x221E #xB1 #x00B1 #xB2 #x2264 #xB3 #x2265 #xB4 #x00A5 #xB5 #x00B5 #xB6 #x2202 #xB7 #x2211 #xB8 #x220F #xB9 #x03C0 #xBA #x222B #xBB #x00AA #xBC #x00BA #xBD #x03A9 #xBE #x00E6 #xBF #x00F8 #xC0 #x00BF #xC1 #x00A1 #xC2 #x00AC #xC3 #x221A #xC4 #x0192 #xC5 #x2248 #xC6 #x2206 #xC7 #x00AB #xC8 #x00BB #xC9 #x2026 #xCA #x00A0 #xCB #x00C0 #xCC #x00C3 #xCD #x00D5 #xCE #x0152 #xCF #x0153 #xD0 #x2103 #xD1 #x2014 #xD2 #x201C #xD3 #x201D #xD4 #x2018 #xD5 #x2019 #xD6 #x00F7 #xD7 #x25CA #xD8 #x00FF #xD9 #x0178 #xDA #x2044 #xDB #x20AC #xDC #x2039 #xDD #x203A #xDE #xFB01 #xDF #xFB02 #xE0 #x2021 #xE1 #x00B7 #xE2 #x201A #xE3 #x201E #xE4 #x2030 #xE5 #x00C2 #xE6 #x00CA #xE7 #x00C1 #xE8 #x00CB #xE9 #x00C8 #xEA #x00CD #xEB #x00CE #xEC #x00CF #xED #x00CC #xEE #x00D3 #xEF #x00D4 #xF0 #xF8FF #xF1 #x00D2 #xF2 #x00DA #xF3 #x00DB #xF4 #x00D9 #xF5 #x0131 #xF6 #x02C6 #xF7 #x02DC #xF8 #x00AF #xF9 #x02D8 #xFA #x02D9 #xFB #x02DA #xFC #x00B8 #xFD #x02DD #xFE #x02DB #xFF #x02C7)) (defconstant +unicode-platform-id+ 0) (defconstant +macintosh-platform-id+ 1) (defconstant +iso-platform-id+ 2) (defconstant +microsoft-platform-id+ 3) (defconstant +custom-platform-id+ 4) (defconstant +unicode-2.0-encoding-id+ 3) (defconstant +microsoft-unicode-bmp-encoding-id+ 1) (defconstant +microsoft-symbol-encoding-id+ 0) (defconstant +macintosh-roman-encoding-id+ 1) ;; Full list of microsoft language IDs is here: ;; http://www.microsoft.com/globaldev/reference/lcid-all.mspx (defconstant +microsoft-us-english-language-id+ #x0409) (defconstant +macintosh-english-language-id+ 1) (defconstant +unicode-language-id+ 0) (defclass name-entry () ((font-loader :initarg :font-loader :accessor font-loader) (platform-id :initarg :platform-id :accessor platform-id) (encoding-id :initarg :encoding-id :accessor encoding-id) (language-id :initarg :language-id :accessor language-id) (name-id :initarg :name-id :accessor name-id) (offset :initarg :offset :accessor offset :documentation "The octet offset within the TrueType file stream of the entry's data. *Not* the same as the offset in the NameRecord structure, which is relative to the start of the string data for the table.") (entry-length :initarg :entry-length :accessor entry-length) (value :reader %value :writer (setf value)) (octets :reader %octets :writer (setf octets)))) (defmethod print-object ((name-entry name-entry) stream) (print-unreadable-object (name-entry stream :type t) (format stream "~A (~A/~A/~D)" (aref *name-identifiers* (name-id name-entry)) (platform-id-name (platform-id name-entry)) (encoding-id-name (platform-id name-entry) (encoding-id name-entry)) (language-id name-entry)))) (defun unicode-octets-to-string (octets) (let ((string (make-string (/ (length octets) 2)))) (flet ((ref16 (i) (+ (ash (aref octets i) 16) (aref octets (1+ i))))) (loop for i from 0 below (length octets) by 2 for j from 0 do (setf (char string j) (code-char (ref16 i)))) string))) (defun macintosh-octets-to-string (octets) (flet ((macroman->unicode (point) (code-char (aref *macroman-translation-table* (1+ (ash point 1)))))) (let ((string (make-string (length octets)))) (dotimes (i (length octets) string) (setf (schar string i) (macroman->unicode (aref octets i))))))) (defgeneric initialize-name-entry (name-entry) (:method (name-entry) (let ((stream (input-stream (font-loader name-entry))) (octets (make-array (entry-length name-entry) :element-type '(unsigned-byte 8))) (value nil) (platform-id (platform-id name-entry))) (file-position stream (offset name-entry)) (read-sequence octets stream) (cond ((or (= platform-id +unicode-platform-id+) (= platform-id +microsoft-platform-id+)) (setf value (unicode-octets-to-string octets))) ((= platform-id +macintosh-platform-id+) (setf value (macintosh-octets-to-string octets))) (t (error 'unsupported-value :location "\"name\" table platform ID" :actual-value platform-id :expected-values (list +unicode-platform-id+ +microsoft-platform-id+ +macintosh-platform-id+)))) (setf (value name-entry) value (octets name-entry) octets)))) (defgeneric value (name-entry) (:method (name-entry) (unless (slot-boundp name-entry 'value) (initialize-name-entry name-entry)) (%value name-entry))) (defgeneric octets (name-entry) (:method (name-entry) (unless (slot-boundp name-entry 'octets) (initialize-name-entry name-entry)) (%octets name-entry))) (defun load-name-info (loader) (seek-to-table "name" loader) (let* ((stream (input-stream loader)) (table-offset (file-position stream)) (format (read-uint16 stream))) (unless (= format 0) (error 'unsupported-format :location "\"name\" table" :actual-value format :expected-values (list 0))) (let* ((count (read-uint16 stream)) (values-offset (read-uint16 stream)) (entries (make-array count))) (setf (name-entries loader) entries) (dotimes (i count) (let ((platform-id (read-uint16 stream)) (encoding-id (read-uint16 stream)) (language-id (read-uint16 stream)) (name-id (read-uint16 stream)) (length (read-uint16 stream)) (offset (read-uint16 stream))) (setf (aref entries i) (make-instance 'name-entry :font-loader loader :platform-id platform-id :encoding-id encoding-id :language-id language-id :name-id name-id :entry-length length :offset (+ table-offset values-offset offset)))))))) ;;; ;;; Fetching info out of the name-entry vector ;;; (defun name-identifier-id (symbol) (let ((id (position symbol *name-identifiers*))) (if id id (error "Unknown NAME identifier: ~S" symbol)))) (defmethod find-name-entry (platform-id encoding-id language-id name-id (font-loader font-loader)) ;; FIXME: this vector is sorted by platform ID, encoding ID, ;; language ID, and name ID, in that order. Could bisect if it ;; mattered. (loop for name-entry across (name-entries font-loader) when (and (or (null platform-id) (= (platform-id name-entry) platform-id)) (or (null encoding-id) (= (encoding-id name-entry) encoding-id)) (or (null language-id) (= (language-id name-entry) language-id)) (or (null name-id) (= (name-id name-entry) name-id))) return name-entry)) (defmethod name-entry-value (name-designator (font-loader font-loader)) (let* ((name-id (etypecase name-designator (keyword (name-identifier-id name-designator)) (integer name-designator))) (entry (or (find-name-entry +unicode-platform-id+ +unicode-2.0-encoding-id+ +unicode-language-id+ name-id font-loader) (find-name-entry +microsoft-platform-id+ nil +microsoft-us-english-language-id+ name-id font-loader) (find-name-entry +macintosh-platform-id+ +macintosh-roman-encoding-id+ +macintosh-english-language-id+ name-id font-loader)))) (when entry (value entry)))) (defmethod postscript-name ((font-loader font-loader)) (name-entry-value :postscript-name font-loader)) (defmethod family-name ((font-loader font-loader)) (name-entry-value :font-family font-loader)) (defmethod subfamily-name ((font-loader font-loader)) (name-entry-value :font-subfamily font-loader)) (defmethod full-name ((font-loader font-loader)) (name-entry-value :full-name font-loader))
15,126
Common Lisp
.lisp
563
20.083481
83
0.58292
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
52dd6fba76da768c291275bc4a055777a03521f6bafc20454c806857e82d5b53
42,802
[ -1 ]
42,803
cmap.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/cmap.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "cmap" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/cmap ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6cmap.html ;;; ;;; $Id: cmap.lisp,v 1.15 2006/03/23 22:23:32 xach Exp $ (in-package #:zpb-ttf) (deftype cmap-value-table () `(array (unsigned-byte 16) (*))) ;;; FIXME: "unicode-cmap" is actually a format 4 character map that ;;; happens to currently be loaded from a Unicode-compatible ;;; subtable. However, other character maps (like Microsoft's Symbol ;;; encoding) also use format 4 and could be loaded with these ;;; "unicode" objects and functions. (defclass unicode-cmap () ((segment-count :initarg :segment-count :reader segment-count) (end-codes :initarg :end-codes :reader end-codes) (start-codes :initarg :start-codes :reader start-codes) (id-deltas :initarg :id-deltas :reader id-deltas) (id-range-offsets :initarg :id-range-offsets :reader id-range-offsets) (glyph-indexes :initarg :glyph-indexes :accessor glyph-indexes))) (defun load-unicode-cmap (stream) "Load a Unicode character map of type 4 from STREAM starting at the current offset." (let ((format (read-uint16 stream))) (when (/= format 4) (error 'unsupported-format :location "\"cmap\" subtable" :actual-value format :expected-values (list 4)))) (let ((table-start (- (file-position stream) 2)) (subtable-length (read-uint16 stream)) (language-code (read-uint16 stream)) (segment-count (/ (read-uint16 stream) 2)) (search-range (read-uint16 stream)) (entry-selector (read-uint16 stream)) (range-shift (read-uint16 stream))) (declare (ignore language-code search-range entry-selector range-shift)) (flet ((make-and-load-array (&optional (size segment-count)) (loop with array = (make-array size :element-type '(unsigned-byte 16) :initial-element 0) for i below size do (setf (aref array i) (read-uint16 stream)) finally (return array))) (make-signed (i) (if (logbitp 15 i) (1- (- (logandc2 #xFFFF i))) i))) (let ((end-codes (make-and-load-array)) (pad (read-uint16 stream)) (start-codes (make-and-load-array)) (id-deltas (make-and-load-array)) (id-range-offsets (make-and-load-array)) (glyph-index-array-size (/ (- subtable-length (- (file-position stream) table-start)) 2))) (declare (ignore pad)) (make-instance 'unicode-cmap :segment-count segment-count :end-codes end-codes :start-codes start-codes ;; these are really signed, so sign them :id-deltas (map 'vector #'make-signed id-deltas) :id-range-offsets id-range-offsets :glyph-indexes (make-and-load-array glyph-index-array-size)))))) (defmethod invert-character-map (font-loader) "Return a vector mapping font indexes to code points." (with-slots (start-codes end-codes) (character-map font-loader) (declare (type cmap-value-table start-codes end-codes)) (let ((points (make-array (glyph-count font-loader) :initial-element -1))) (dotimes (i (1- (length end-codes)) points) (loop for j from (aref start-codes i) to (aref end-codes i) for font-index = (code-point-font-index j font-loader) when (minusp (svref points font-index)) do (setf (svref points font-index) j)))))) (defgeneric code-point-font-index (code-point font-loader) (:documentation "Return the index of the Unicode CODE-POINT in FONT-LOADER, if present, otherwise NIL.") (:method (code-point font-loader) (let ((cmap (character-map font-loader))) (with-slots (end-codes start-codes id-deltas id-range-offsets glyph-indexes) cmap (declare (type cmap-value-table end-codes start-codes id-range-offsets glyph-indexes)) (dotimes (i (segment-count cmap) 1) (when (<= code-point (aref end-codes i)) (return (let ((start-code (aref start-codes i)) (id-range-offset (aref id-range-offsets i)) (id-delta (aref id-deltas i))) (cond ((< code-point start-code) 0) ((zerop id-range-offset) (logand #xFFFF (+ code-point id-delta))) (t (let* ((glyph-index-offset (- (+ i (ash id-range-offset -1) (- code-point start-code)) (segment-count cmap))) (glyph-index (aref (glyph-indexes cmap) glyph-index-offset))) (logand #xFFFF (+ glyph-index id-delta))))))))))))) (defgeneric font-index-code-point (glyph-index font-loader) (:documentation "Return the code-point for a given glyph index.") (:method (glyph-index font-loader) (let ((point (aref (inverse-character-map font-loader) glyph-index))) (if (plusp point) point 0)))) (defmethod load-cmap-info ((font-loader font-loader)) (seek-to-table "cmap" font-loader) (with-slots (input-stream) font-loader (let ((start-pos (file-position input-stream)) (version-number (read-uint16 input-stream)) (subtable-count (read-uint16 input-stream)) (foundp nil)) (declare (ignore version-number)) (loop repeat subtable-count for platform-id = (read-uint16 input-stream) for platform-specific-id = (read-uint16 input-stream) for offset = (+ start-pos (read-uint32 input-stream)) when (and (= platform-id +microsoft-platform-id+) (= platform-specific-id +microsoft-unicode-bmp-encoding-id+)) do (file-position input-stream offset) (setf (character-map font-loader) (load-unicode-cmap input-stream)) (setf (inverse-character-map font-loader) (invert-character-map font-loader) foundp t) (return)) (unless foundp (error "Could not find supported character map in font file"))))) (defun available-character-maps (loader) (seek-to-table "cmap" loader) (let ((stream (input-stream loader))) (let ((start-pos (file-position stream)) (version-number (read-uint16 stream)) (subtable-count (read-uint16 stream))) (declare (ignore start-pos)) (assert (zerop version-number)) (dotimes (i subtable-count) (let ((platform-id (read-uint16 stream)) (encoding-id (read-uint16 stream)) (offset (read-uint32 stream))) (declare (ignore offset)) (format t "~D (~A) - ~D (~A)~%" platform-id (platform-id-name platform-id) encoding-id (encoding-id-name platform-id encoding-id)))))))
9,036
Common Lisp
.lisp
185
37.394595
87
0.588275
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
20d58b8fb659702c0e058ae95f02d2fc49e461cc85ad1519761e0376cc425d66
42,803
[ -1 ]
42,804
head.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/head.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "head" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/head ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6head.html ;;; ;;; $Id: head.lisp,v 1.5 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defmethod load-head-info ((font-loader font-loader)) (seek-to-table "head" font-loader) (with-slots (input-stream units/em bounding-box loca-offset-format) font-loader (flet ((skip-bytes (count) (file-position input-stream (+ count (file-position input-stream))))) (let ((version (read-uint32 input-stream))) (check-version "\"head\" table" version #x00010000)) ;; skip fontRevsion and checkSumAdjustment (both uint32) (skip-bytes 8) ;; check the magicNumber (let ((magic-number (read-uint32 input-stream))) (when (/= magic-number #x5F0F3CF5) (error 'bad-magic :location "\"head\" table" :expected-values (list #x5F0F3CF5) :actual-value magic-number))) ;; skip flags (skip-bytes 2) (setf units/em (read-uint16 input-stream)) ;; skip created and modified dates (skip-bytes 16) (setf bounding-box (vector (read-int16 input-stream) (read-int16 input-stream) (read-int16 input-stream) (read-int16 input-stream))) ;; skip macStyle, lowestRecPPEM, fontDirectionHint (skip-bytes 6) ;; set the loca-offset-format (if (zerop (read-int16 input-stream)) (setf loca-offset-format :short) (setf loca-offset-format :long)))))
3,092
Common Lisp
.lisp
66
40.409091
76
0.663029
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
b539ed04849056f09cdeef9254ec85d8790e5d95deb7f772d2ae82a02b6b93fc
42,804
[ -1 ]
42,805
loca.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/loca.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "loca" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/loca ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6loca.html ;;; ;;; $Id: loca.lisp,v 1.3 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defmethod load-loca-info ((font-loader font-loader)) (seek-to-table "loca" font-loader) (with-slots (input-stream glyph-locations glyph-count loca-offset-format) font-loader (setf glyph-locations (make-array (1+ glyph-count))) (dotimes (i (1+ glyph-count)) (setf (svref glyph-locations i) (if (eql loca-offset-format :short) (* (read-uint16 input-stream) 2) (read-uint32 input-stream)))))) (defmethod glyph-location (index (font-loader font-loader)) (aref (glyph-locations font-loader) index)) (defmethod glyph-length (index (font-loader font-loader)) (with-slots (glyph-locations) font-loader (- (aref glyph-locations (1+ index)) (aref glyph-locations index))))
2,377
Common Lisp
.lisp
50
44.68
75
0.721481
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
cf65b366be5bb7ef33d2b4adfd749accf5f32971a518d5c26aa48ed948ebc656
42,805
[ -1 ]
42,806
maxp.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/maxp.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "maxp" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/maxp ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6maxp.html ;;; ;;; $Id: maxp.lisp,v 1.3 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defmethod load-maxp-info ((font-loader font-loader)) (seek-to-table "maxp" font-loader) (with-slots (input-stream glyph-count) font-loader (let ((version (read-uint32 input-stream))) (check-version "\"maxp\" table" version #x00010000) (setf glyph-count (read-uint16 input-stream)))))
1,927
Common Lisp
.lisp
39
47.846154
70
0.73913
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
18f2e0e68595f101f6ae3e54b00c9185160cdacb247ed39f4f92bfecd04db991
42,806
[ -1 ]
42,807
font-loader-interface.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/font-loader-interface.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Interface functions for creating, initializing, and closing a ;;; FONT-LOADER object. ;;; ;;; $Id: font-loader-interface.lisp,v 1.6 2006/03/23 22:20:35 xach Exp $ (in-package #:zpb-ttf) (defun arrange-finalization (object stream) (flet ((quietly-close (&optional object) (declare (ignore object)) (ignore-errors (close stream)))) #+sbcl (sb-ext:finalize object #'quietly-close) #+cmucl (ext:finalize object #'quietly-close) #+clisp (ext:finalize object #'quietly-close) #+allegro (excl:schedule-finalization object #'quietly-close))) ;;; ;;; FIXME: move most/all of this stuff into initialize-instance ;;; (defun open-font-loader-from-stream (input-stream &key (collection-index 0)) (let ((magic (read-uint32 input-stream)) (font-count)) (when (/= magic #x00010000 #x74727565 #x74746366) (error 'bad-magic :location "font header" :expected-values (list #x00010000 #x74727565 #x74746366) :actual-value magic)) (when (= magic #x74746366) (let ((version (read-uint32 input-stream))) (check-version "ttc header" version #x00010000 #x00020000) (setf font-count (read-uint32 input-stream)) (let* ((offset-table (make-array font-count)) (dsig)) (when (> collection-index font-count) (error 'unsupported-value :description "Font index out of range" :actual-value collection-index :expected-values (list font-count))) (loop for i below font-count do (setf (aref offset-table i) (read-uint32 input-stream))) (when (= version #x00020000) (let ((flag (read-uint32 input-stream)) (length (read-uint32 input-stream)) (offset (read-uint32 input-stream))) (list flag length offset) (when (= #x44534947 flag) (setf dsig (list length offset))))) ;; seek to font offset table (file-position input-stream (aref offset-table collection-index)) (let ((magic2 (read-uint32 input-stream))) (when (/= magic2 #x00010000 #x74727565) (error 'bad-magic :location "font header" :expected-values (list #x00010000 #x74727565) :actual-value magic2)))))) (let* ((table-count (read-uint16 input-stream)) (font-loader (make-instance 'font-loader :input-stream input-stream :table-count table-count :collection-font-cont font-count :collection-font-index (when font-count collection-index)))) ;; skip the unused stuff: ;; searchRange, entrySelector, rangeShift (read-uint16 input-stream) (read-uint16 input-stream) (read-uint16 input-stream) (loop repeat table-count for tag = (read-uint32 input-stream) for checksum = (read-uint32 input-stream) for offset = (read-uint32 input-stream) for size = (read-uint32 input-stream) do (setf (gethash tag (tables font-loader)) (make-instance 'table-info :offset offset :name (number->tag tag) :size size))) (load-maxp-info font-loader) (load-head-info font-loader) (load-kern-info font-loader) (load-loca-info font-loader) (load-name-info font-loader) (load-cmap-info font-loader) (load-post-info font-loader) (load-hhea-info font-loader) (load-hmtx-info font-loader) (setf (glyph-cache font-loader) (make-array (glyph-count font-loader) :initial-element nil)) font-loader))) (defun open-font-loader-from-file (thing &key (collection-index 0)) (let ((stream (open thing :direction :input :element-type '(unsigned-byte 8)))) (let ((font-loader (open-font-loader-from-stream stream :collection-index collection-index))) (arrange-finalization font-loader stream) font-loader))) (defun open-font-loader (thing &key (collection-index 0)) (typecase thing (font-loader (cond ((= collection-index (collection-font-index thing)) (unless (open-stream-p (input-stream thing)) (setf (input-stream thing) (open (input-stream thing)))) thing) (t (open-font-loader-from-file (input-stream thing) :collection-index collection-index)))) (stream (if (open-stream-p thing) (open-font-loader-from-stream thing :collection-index collection-index) (error "~A is not an open stream" thing))) (t (open-font-loader-from-file thing :collection-index collection-index)))) (defun close-font-loader (loader) (close (input-stream loader))) (defmacro with-font-loader ((loader file &key (collection-index 0)) &body body) `(let (,loader) (unwind-protect (progn (setf ,loader (open-font-loader ,file :collection-index ,collection-index)) ,@body) (when ,loader (close-font-loader ,loader)))))
6,897
Common Lisp
.lisp
153
35.111111
80
0.608114
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
7c44b85d8bab788d0879f32b84f2a336fcdaaa76db7a8c2992c420f5c88a4b77
42,807
[ -1 ]
42,808
bounding-box.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/bounding-box.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;;; ;;;; Bounding boxes, which are common to both the overall font and ;;;; individual glyphs. ;;;; ;;;; $Id: bounding-box.lisp,v 1.2 2006/02/18 23:13:43 xach Exp $ (in-package :zpb-ttf) (defgeneric bounding-box (object)) (macrolet ((bbox-accessor (name index) `(progn (defgeneric ,name (object) (:method (object) (aref (bounding-box object) ,index))) (defgeneric (setf ,name) (new-value object) (:method (new-value object) (setf (aref (bounding-box object) ,index) new-value)))))) (bbox-accessor xmin 0) (bbox-accessor ymin 1) (bbox-accessor xmax 2) (bbox-accessor ymax 3)) (defmethod bounding-box ((object array)) object)
2,114
Common Lisp
.lisp
46
42.021739
77
0.699128
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
4355543f7a5260cd2af0d69e185a1c1770c6be94a0c5fbef75f66a432fc3fa5e
42,808
[ -1 ]
42,809
hmtx.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/hmtx.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "hmtx" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/hmtx ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hmtx.html ;;; ;;; $Id: hmtx.lisp,v 1.3 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defmethod load-hmtx-info ((font-loader font-loader)) (let* ((horizontal-metrics-count (horizontal-metrics-count font-loader)) (advance-widths (make-array horizontal-metrics-count)) (left-side-bearings (make-array horizontal-metrics-count))) (seek-to-table "hmtx" font-loader) (with-slots (input-stream) font-loader (dotimes (i horizontal-metrics-count) (setf (svref advance-widths i) (read-uint16 input-stream)) (setf (svref left-side-bearings i) (read-int16 input-stream)))) (setf (advance-widths font-loader) advance-widths (left-side-bearings font-loader) left-side-bearings)))
2,268
Common Lisp
.lisp
44
49.045455
74
0.734023
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
64fce2483cd8df5b99a075ca0b098b052432e425ab0f7a6db269c68dcbfedd43
42,809
[ -1 ]
42,810
hhea.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/hhea.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Loading data from the "hhea" table. ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/hhea ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html ;;; ;;; $Id: hhea.lisp,v 1.4 2006/02/18 23:13:43 xach Exp $ (in-package #:zpb-ttf) (defmethod load-hhea-info ((font-loader font-loader)) (seek-to-table "hhea" font-loader) (with-slots (input-stream ascender descender line-gap) font-loader (let ((version (read-fixed input-stream))) (check-version "\"hhea\" table" version #x00010000)) (setf ascender (read-fword input-stream) descender (read-fword input-stream) line-gap (read-fword input-stream)))) (defmethod horizontal-metrics-count ((font-loader font-loader)) (seek-to-table "hhea" font-loader) (with-slots (input-stream) font-loader ;; Skip to the end, since all we care about is the last item (advance-file-position input-stream 34) (read-uint16 input-stream)))
2,318
Common Lisp
.lisp
48
45.979167
70
0.733569
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e13519a53d1fc156c1c80d85ad942b32a373d744707c413fb8aae9ea1f85e69d
42,810
[ -1 ]
42,811
kern.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/zpb-ttf-release-1.0.4/kern.lisp
;;; Copyright (c) 2006 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; "kern" table functions ;;; ;;; https://docs.microsoft.com/en-us/typography/opentype/spec/kern ;;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html ;;; ;;; $Id: kern.lisp,v 1.8 2006/03/28 14:38:37 xach Exp $ (in-package #:zpb-ttf) (defun load-kerning-format-1 (table stream) "Return a hash table keyed on a UINT32 key that represents the glyph index in the left and right halves with a value of the kerning distance between the pair." (let ((pair-count (read-uint16 stream)) (search-range (read-uint16 stream)) (entry-selector (read-uint16 stream)) (range-shift (read-uint16 stream))) (declare (ignore search-range entry-selector range-shift)) (dotimes (i pair-count) (setf (gethash (read-uint32 stream) table) (read-int16 stream))))) (defmethod load-kerning-subtable ((font-loader font-loader) format) (when (/= 1 format) (error 'unsupported-format :description "kerning subtable" :size 1 :expected-values (list 1) :actual-value format)) (load-kerning-format-1 (kerning-table font-loader) (input-stream font-loader))) (defmethod load-kern-info ((font-loader font-loader)) (when (table-exists-p "kern" font-loader) (seek-to-table "kern" font-loader) (let* ((stream (input-stream font-loader)) (maybe-version (read-uint16 stream)) (maybe-table-count (read-uint16 stream)) (version 0) (table-count 0)) ;; These shenanegins are because Apple documents one style of ;; kern table and Microsoft documents another. This code ;; implements Microsoft's version. ;; See: ;; http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html ;; https://docs.microsoft.com/en-us/typography/opentype/spec/kern (if (zerop version) (setf version maybe-version table-count maybe-table-count) (setf version (logand (ash maybe-version 16) maybe-table-count) table-count (read-uint32 stream))) (check-version "\"kern\" table" version 0) (dotimes (i table-count) (let ((version (read-uint16 stream)) (length (read-uint16 stream)) (coverage-flags (read-uint8 stream)) (format (read-uint8 stream))) (declare (ignore version length coverage-flags)) (load-kerning-subtable font-loader format)))))) (defmethod all-kerning-pairs ((font-loader font-loader)) (let ((pairs nil)) (maphash (lambda (k v) (let* ((left-index (ldb (byte 16 16) k)) (right-index (ldb (byte 16 0) k)) (left (index-glyph left-index font-loader)) (right (index-glyph right-index font-loader))) (push (list left right v) pairs))) (kerning-table font-loader)) pairs))
4,274
Common Lisp
.lisp
91
40.615385
73
0.668262
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
4eea8d95f746c7d01de773621c47419932d9409db7dbf558477adb1a3246bcdc
42,811
[ -1 ]
42,812
impl-lispworks.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-lispworks.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Lispworks CL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (fli:fill-foreign-object pointer :nelems length :byte value) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (fli:replace-foreign-object dst-ptr src-ptr :nelems length) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (make-array length :element-type element-type :allocation :static)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (let ((ptr (null-pointer))) (fli::set-dynamic-lisp-array-pointer ptr vector offset))) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (declare (ignore vector)) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) ,@body))))
2,125
Common Lisp
.lisp
46
40.195652
74
0.688707
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a5b2b8de06321a110e41c9c57dff4e834b282628808949ef03dcdd3db7114986
42,812
[ 304455 ]
42,813
impl-ecl.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-ecl.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- ECL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (foreign-funcall "memset" :pointer pointer :int value :size length :pointer) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (foreign-funcall "memcpy" :pointer dst-ptr :pointer src-ptr :size length :pointer) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (make-array length :element-type element-type)) (declaim (inline static-vector-address)) ;;; ECL, built with the Boehm GC never moves allocated data, so this is easy (defun static-vector-address (vector) "Return a foreign pointer to VECTOR(including its header). VECTOR must be a vector created by MAKE-STATIC-VECTOR." (si:foreign-data-address (si:make-foreign-data-from-array vector))) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (inc-pointer (make-pointer (static-vector-address vector)) offset)) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (declare (ignore vector)) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) ,@body))))
2,446
Common Lisp
.lisp
51
42.647059
84
0.705069
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
03e75469209b5a1f9f9b426e724626f4b1767c87c66402be05f3cbd07a67d37a
42,813
[ 27865 ]
42,814
impl-sbcl.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-sbcl.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- SBCL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (foreign-funcall "memset" :pointer pointer :int value :size length :pointer) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (foreign-funcall "memcpy" :pointer dst-ptr :pointer src-ptr :size length :pointer) dst-ptr) (defconstant +array-header-size+ (* sb-vm:vector-data-offset sb-vm:n-word-bytes)) (declaim (inline vector-widetag-and-n-bits)) (defun vector-widetag-and-n-bits (type) (let ((upgraded-type (upgraded-array-element-type type))) (case upgraded-type ((nil t) (error "~A is not a specializable array element type" type)) (t #+#.(cl:if (cl:find-symbol "%VECTOR-WIDETAG-AND-N-BITS" "SB-IMPL") '(and) '(or)) (sb-impl::%vector-widetag-and-n-bits type) #+#.(cl:if (cl:find-symbol "%VECTOR-WIDETAG-AND-N-BITS-SHIFT" "SB-IMPL") '(and) '(or)) (multiple-value-bind (widetag shift) (sb-impl::%vector-widetag-and-n-bits-shift type) (values widetag (ash 1 shift))))))) (defun %allocate-static-vector (length element-type) (labels ((string-widetag-p (widetag) (= widetag sb-vm:simple-character-string-widetag)) (allocation-size (length widetag n-bits) (+ (* 2 sb-vm:n-word-bytes (ceiling (* (if (string-widetag-p widetag) (1+ length) ; for the final #\Null length) n-bits) (* 2 sb-vm:n-word-bits))) +array-header-size+))) (multiple-value-bind (widetag n-bits) (vector-widetag-and-n-bits element-type) (let* ((size (allocation-size length widetag n-bits)) (pointer (foreign-alloc :char :count size))) (setf (sb-sys:sap-ref-word pointer 0) widetag (sb-sys:sap-ref-word pointer sb-vm:n-word-bytes) (sb-vm:fixnumize length)) (sb-kernel:%make-lisp-obj (logior (pointer-address pointer) sb-vm:other-pointer-lowtag)))))) (declaim (inline static-vector-address)) (defun static-vector-address (vector) "Return a foreign pointer to VECTOR(including its header). VECTOR must be a vector created by MAKE-STATIC-VECTOR." (logandc2 (sb-kernel:get-lisp-obj-address vector) sb-vm:lowtag-mask)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (make-pointer (+ (static-vector-address vector) +array-header-size+ offset))) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (declare (sb-ext:muffle-conditions sb-ext:compiler-note)) (foreign-free (make-pointer (static-vector-address vector))) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(sb-sys:without-interrupts (let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) (unwind-protect (sb-sys:with-local-interrupts ,@body) (when ,var (free-static-vector ,var))))))))
4,332
Common Lisp
.lisp
89
39.685393
88
0.63005
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
60df940787c2d406f1f98e1f859a4ad27a802fd3624a37709627943f1310226d
42,814
[ 346344 ]
42,815
impl-abcl.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-abcl.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Armed Bear CL implementation ;;; (in-package :static-vectors) #-nio (error "For allocating memory via malloc() we need the :NIO-BUFFER argument to CL:MAKE-ARRAY available in abcl-1.6.2-dev and the upcoming abcl-1.7.0.") (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) (foreign-funcall "memset" :pointer pointer :int value :size length :pointer) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (foreign-funcall "memcpy" :pointer dst-ptr :pointer src-ptr :size length :pointer) dst-ptr) ;;; HACK for now (defvar *static-vector-pointer* (make-hash-table :weakness :value)) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (let* ((type (first element-type)) (bits-per-byte (second element-type)) (bytes-per-element ;; ehh, not going to work well for element type not of size 8, 16, or 32 (ceiling bits-per-byte 8))) (unless (subtypep element-type '(or (unsigned-byte 8) (unsigned-byte 16) (unsigned-byte 32))) (signal 'type-error :datum element-type :expected-type '(or (unsigned-byte 8) (unsigned-byte 16) (unsigned-byte 32)))) (let* ((bytes (* length bytes-per-element)) (heap-pointer (jss:new "com.sun.jna.Memory" bytes)) (bytebuffer (#"getByteBuffer" heap-pointer 0 bytes)) (static-vector (make-array length :element-type element-type :nio-buffer bytebuffer))) (setf (gethash static-vector *static-vector-pointer*) heap-pointer) (values static-vector heap-pointer)))) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) ;;; FIXME collapse it (let ((expected-type 'vector)) ;; FIXME tighten (unless (typep vector expected-type) (signal 'simple-type-error vector expected-type)) (let ((pointer (gethash vector *static-vector-pointer*))) (unless pointer (signal 'simple-error "vector ~a doesn't have an associated pointer to malloc()-ed memory" vector)) (cffi-sys:inc-pointer pointer offset)))) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (let ((pointer (gethash vector *static-vector-pointer*))) (when pointer (cffi-sys:foreign-free pointer) (setf (gethash vector *static-vector-pointer*) nil)))) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) (unwind-protect (locally ,@body) (when ,var (free-static-vector ,var)))))))
3,924
Common Lisp
.lisp
86
37.034884
107
0.633847
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
ceb42b602976ebe1272709673d90ea4f9d507d3ce6609dd8168911b193453b2b
42,815
[ 3803 ]
42,816
impl-clasp.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-clasp.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Clasp implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (sys:fill-foreign-memory pointer length value) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (sys:replace-foreign-memory dst-ptr src-ptr length) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (sys:make-static-vector (upgraded-array-element-type element-type) length)) (declaim (inline static-vector-address)) (defun static-vector-address (vector) "Return a foreign pointer to VECTOR(including its header). VECTOR must be a vector created by MAKE-STATIC-VECTOR." (sys:static-vector-address vector)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (sys:static-vector-pointer vector offset)) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (gctools:deallocate-unmanaged-instance vector) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) (unwind-protect (locally ,@body) (when ,var (free-static-vector ,var)))))))
2,389
Common Lisp
.lisp
51
41.098039
77
0.700858
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
f044d5252cdd4c5a16a5fdfb46d2e55a57028c11faf53fe6343e382ab82341b8
42,816
[ 490518 ]
42,817
constantp.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/constantp.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Checking for compile-time constance and evaluating such forms ;;; (in-package :static-vectors) (defun quotedp (form) (and (listp form) (= 2 (length form)) (eql 'quote (car form)))) (defun constantp (form &optional env) (let ((form (if (symbolp form) (macroexpand form env) form))) (or (quotedp form) (cl:constantp form)))) (defun eval-constant (form &optional env) (declare (ignorable env)) (cond ((quotedp form) (second form)) (t #+clozure (ccl::eval-constant form) #+sbcl (sb-int:constant-form-value form env) #-(or clozure sbcl) (eval form)))) (defun canonicalize-args (env element-type length) (let* ((eltype-spec (or (and (constantp element-type) (ignore-errors (upgraded-array-element-type (eval-constant element-type)))) '*)) (length-spec (if (constantp length env) `,(eval-constant length env) '*)) (type-decl (if (eql '* eltype-spec) 'simple-array `(simple-array ,eltype-spec (,length-spec))))) (values (if (eql '* eltype-spec) element-type `(quote ,eltype-spec)) (if (eql '* length-spec) length length-spec) type-decl)))
1,542
Common Lisp
.lisp
46
22.695652
70
0.503018
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
eb3a61e2f812a1b65d98cc3b36cd427396ba8ec4a3255b986ae2237331fda0c9
42,817
[ 433640 ]
42,818
cffi-type-translator.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/cffi-type-translator.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- CFFI type translator ;;; (in-package :static-vectors) (defctype static-vector (:wrapper :pointer :to-c static-vector-pointer))
190
Common Lisp
.lisp
7
25.571429
50
0.668508
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
0eb8e0b347ca2b7aebb0bbae1e5d80db5fa0d7d8541fad6884aa74cb819d27ac
42,818
[ 153110 ]
42,819
impl-clozure.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-clozure.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- ClozureCL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (#_memset pointer value length) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (#_memcpy dst-ptr src-ptr length) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (ccl:make-heap-ivector length element-type)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (unless (typep vector 'ccl::ivector) (ccl::report-bad-arg vector 'ccl::ivector)) (let ((ptr (null-pointer))) (inc-pointer (ccl::%vect-data-to-macptr vector ptr) offset))) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (ccl:dispose-heap-ivector vector) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) (unwind-protect (locally ,@body) (when ,var (free-static-vector ,var)))))))
2,219
Common Lisp
.lisp
49
39.244898
74
0.680536
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
49ef8f7ae4303505ce4cc758ec8ed58021d69504265fd7d668be6bccb6cf7a24
42,819
[ 302228 ]
42,820
impl-allegro.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-allegro.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Allegro CL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (foreign-funcall "memset" :pointer pointer :int value :size length :pointer) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (foreign-funcall "memcpy" :pointer dst-ptr :pointer src-ptr :size length :pointer) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (make-array length :element-type element-type :allocation :static)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (inc-pointer (ff:fslot-address-typed :unsigned-char :lisp vector) offset)) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (excl:aclfree (excl:lispval-other-to-address vector)) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) (unwind-protect (locally ,@body) (when ,var (free-static-vector ,var)))))))
2,265
Common Lisp
.lisp
47
41.851064
84
0.686115
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
4733c18806e1e9875041e8b51471cbe62ae8e90e1491f8b150e6f3c52fb29981
42,820
[ 365220 ]
42,821
pkgdcl.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/pkgdcl.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Package definition ;;; (in-package :common-lisp-user) (defpackage :static-vectors (:use #:common-lisp :alexandria :cffi) (:shadow #:constantp) (:export ;; Constructors and destructors #:make-static-vector #:free-static-vector #:with-static-vector #:with-static-vectors ;; Accessors #:static-vector-pointer ;; CFFI wrapper type #:static-vector ;; Foreign memory operations #:replace-foreign-memory #:fill-foreign-memory ))
531
Common Lisp
.lisp
22
20.863636
46
0.678571
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
778adfdbb69bf9537cabb3d5822d0ec653cf9f0dd621c354bb70e6b7277c9874
42,821
[ 479315 ]
42,822
impl-cmucl.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/impl-cmucl.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- CMUCL implementation ;;; (in-package :static-vectors) (declaim (inline fill-foreign-memory)) (defun fill-foreign-memory (pointer length value) "Fill LENGTH octets in foreign memory area POINTER with VALUE." (foreign-funcall "memset" :pointer pointer :int value :size length :pointer) pointer) (declaim (inline replace-foreign-memory)) (defun replace-foreign-memory (dst-ptr src-ptr length) "Copy LENGTH octets from foreign memory area SRC-PTR to DST-PTR." (foreign-funcall "memcpy" :pointer dst-ptr :pointer src-ptr :size length :pointer) dst-ptr) (declaim (inline %allocate-static-vector)) (defun %allocate-static-vector (length element-type) (make-array length :element-type element-type :allocation :malloc)) (declaim (inline static-vector-pointer)) (defun static-vector-pointer (vector &key (offset 0)) "Return a foreign pointer to the beginning of VECTOR + OFFSET octets. VECTOR must be a vector created by MAKE-STATIC-VECTOR." (check-type offset unsigned-byte) (inc-pointer (sys:vector-sap vector) offset)) (declaim (inline free-static-vector)) (defun free-static-vector (vector) "Free VECTOR, which must be a vector created by MAKE-STATIC-VECTOR." (declare (ignore vector)) (values)) (defmacro with-static-vector ((var length &rest args &key (element-type ''(unsigned-byte 8)) initial-contents initial-element) &body body &environment env) "Bind PTR-VAR to a static vector of length LENGTH and execute BODY within its dynamic extent. The vector is freed upon exit." (declare (ignorable element-type initial-contents initial-element)) (multiple-value-bind (real-element-type length type-spec) (canonicalize-args env element-type length) (let ((args (copy-list args))) (remf args :element-type) `(let ((,var (make-static-vector ,length ,@args :element-type ,real-element-type))) (declare (type ,type-spec ,var)) ,@body))))
2,113
Common Lisp
.lisp
45
40.933333
84
0.689471
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
01e9ce6cfa19a900b295e0a15afef0638f7ebc6a491c9f66fba00094168212a3
42,822
[ 225470 ]
42,823
constructor.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/constructor.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- MAKE-STATIC-VECTOR ;;; (in-package :static-vectors) (declaim (inline check-initial-element)) (defun check-initial-element (element-type initial-element) (when (not (typep initial-element element-type)) ;; FIXME: signal SUBTYPE-ERROR (error "MAKE-STATIC-VECTOR: The type of :INITIAL-ELEMENT ~S is not a subtype ~ of the array's :ELEMENT-TYPE ~S" initial-element element-type))) (declaim (inline check-initial-contents)) (defun check-initial-contents (length initial-contents) (let ((initial-contents-length (length initial-contents))) (when (/= length initial-contents-length) ;; FIXME: signal TYPE-ERROR (error "MAKE-STATIC-VECTOR: There are ~A elements in the :INITIAL-CONTENTS, ~ but requested vector length is ~A." initial-contents-length length)))) (declaim (inline check-initialization-arguments)) (defun check-initialization-arguments (initial-element-p initial-contents-p) (when (and initial-element-p initial-contents-p) ;; FIXME: signal ARGUMENT-LIST-ERROR (error "MAKE-STATIC-VECTOR: You must not specify both ~ :INITIAL-ELEMENT and :INITIAL-CONTENTS"))) (defun check-arguments (length element-type initial-element initial-element-p initial-contents initial-contents-p) (check-initialization-arguments initial-element-p initial-contents-p) (check-type length non-negative-fixnum) (when initial-element-p (check-initial-element element-type initial-element)) (when initial-contents-p (check-initial-contents length initial-contents))) (declaim (inline make-static-vector)) (defun make-static-vector (length &key (element-type '(unsigned-byte 8)) (initial-element nil initial-element-p) (initial-contents nil initial-contents-p)) "Create a simple vector of length LENGTH and type ELEMENT-TYPE which will not be moved by the garbage collector. The vector might be allocated in foreign memory so you must always call FREE-STATIC-VECTOR to free it." (declare #+sbcl (sb-ext:muffle-conditions sb-ext:compiler-note) (optimize speed)) (check-arguments length element-type initial-element initial-element-p initial-contents initial-contents-p) (let ((vector (%allocate-static-vector length element-type))) (if initial-element-p (fill vector initial-element) (replace vector initial-contents)))) (defmacro with-static-vectors (((var length &rest args) &rest more-clauses) &body body) "Allocate multiple static vectors at once." `(with-static-vector (,var ,length ,@args) ,@(if more-clauses `((with-static-vectors ,more-clauses ,@body)) body)))
2,835
Common Lisp
.lisp
59
41.423729
83
0.694113
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a18ad2ad7afcf19622d518f0732dc4c40c64d40d91a79368b036f5ac9622b701
42,823
[ 243231 ]
42,824
ffi-types.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/src/ffi-types.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- Grovel FFI types ;;; (in-package :static-vectors) (ctype size-t "size_t")
135
Common Lisp
.lisp
6
21.166667
46
0.598425
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
bab346b96dfe621a5921fcf2ba4e3e8ba2367b076bfd003b48a20af50a0be753
42,824
[ 159255 ]
42,825
static-vectors-tests.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/static-vectors-v1.8.9/tests/static-vectors-tests.lisp
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; --- FiveAM Tests ;;; (defpackage :static-vectors/test (:use #:cl #:static-vectors #:fiveam)) (in-package :static-vectors/test) (in-suite* :static-vectors) (test (make-static-vector.defaults :compile-at :definition-time) (let ((v (make-static-vector 5))) (is (= 5 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 8)))))) (test (make-static-vector.element-type.non-literal :compile-at :definition-time) (let* ((element-type '(unsigned-byte 16)) (v (make-static-vector 5 :element-type element-type))) (is (= 5 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 16)))))) (test (make-static-vector.defaults.notinline :compile-at :definition-time) (locally (declare (notinline make-static-vector)) (let ((v (make-static-vector 5))) (is (equal 5 (length v)))))) (test (make-static-vector.initial-element.notinline :compile-at :definition-time) (locally (declare (notinline make-static-vector)) (let ((v (make-static-vector 5 :initial-element 3))) (is (equal 5 (length v))) (is (not (find 3 v :test-not #'=)))))) (test (make-static-vector.initial-contents.notinline :compile-at :definition-time) (locally (declare (notinline make-static-vector)) (let ((v (make-static-vector 5 :initial-contents '(1 2 3 4 5)))) (is (equal 5 (length v))) (is (not (mismatch v '(1 2 3 4 5))))))) (test (with-static-vector.defaults :compile-at :definition-time) (with-static-vector (v 5) (is (= 5 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 8)))))) (test (with-static-vector.element-type.literal :compile-at :definition-time) (with-static-vector (v 3 :element-type '(unsigned-byte 16)) (is (= 3 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 16)))))) (test (with-static-vector.element-type.non-literal :compile-at :definition-time) (let ((element-type '(unsigned-byte 16))) (with-static-vector (v 3 :element-type element-type) (is (= 3 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 16))))))) (test (with-static-vector.initial-element.non-literal :compile-at :definition-time) (let ((element-type '(unsigned-byte 16)) (initial-element 5)) (with-static-vector (v 3 :element-type element-type :initial-element initial-element) (is (= 3 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 16)))) (is (= 5 (aref v 0)))))) (test (with-static-vector.initial-contents.non-literal :compile-at :definition-time) (let ((element-type '(unsigned-byte 16)) (initial-contents '(1 2 3))) (with-static-vector (v 3 :element-type element-type :initial-contents initial-contents) (is (= 3 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 16)))) (is (every #'= v initial-contents))))) (deftype eltype () '(unsigned-byte 32)) (test (with-static-vector.element-type.deftype :compile-at :definition-time) (with-static-vector (v 3 :element-type 'eltype) (is (= 3 (length v))) (is (equal (array-element-type v) (upgraded-array-element-type '(unsigned-byte 32)))))) (test (with-static-vector.initial-element :compile-at :definition-time) (with-static-vector (v 3 :initial-element 7) (is (= 3 (length v))) (is (equalp v #(7 7 7))))) (test (with-static-vector.initial-contents :compile-at :definition-time) (with-static-vector (v 3 :initial-contents '(3 14 29)) (is (= 3 (length v))) (is (equalp v #(3 14 29))))) (test (with-static-vectors.initialization :compile-at :definition-time) (with-static-vectors ((v1 3 :initial-element 7) (v2 5 :initial-contents '(1 2 3 4 5))) (is (equalp v1 #(7 7 7))) (is (equalp v2 #(1 2 3 4 5)))))
4,434
Common Lisp
.lisp
112
32.339286
68
0.603857
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
8edac609cf03e5e36a4042bad5b197c62cc442f1ed78666ec6ff6f0a9c85ce26
42,825
[ 230603 ]
42,826
ssl-verify-test.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/ssl-verify-test.lisp
;;; Copyright (C) 2011 David Lichteblau ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package"))) (in-package :cl+ssl) ;; from cl+ssl/example.lisp (defun read-line-crlf-2 (stream &optional eof-error-p) (let ((s (make-string-output-stream))) (loop for empty = t then nil for c = (read-char stream eof-error-p nil) while (and c (not (eql c #\return))) do (unless (eql c #\newline) (write-char c s)) finally (return (if empty nil (get-output-stream-string s)))))) (defun write-ssl-certificate-names (ssl-stream &optional (output-stream t)) (let* ((ssl (ssl-stream-handle ssl-stream)) (cert (ssl-get-peer-certificate ssl))) (unless (cffi:null-pointer-p cert) (unwind-protect (multiple-value-bind (issuer subject) (x509-certificate-names cert) (format output-stream " issuer: ~a~% subject: ~a~%" issuer subject)) (x509-free cert))))) ;; from cl+ssl/example.lisp (defun test-https-client-2 (host &key (port 443) show-text-p) (let* ((deadline (+ (get-internal-real-time) (* 3 internal-time-units-per-second))) (socket (ccl:make-socket :address-family :internet :connect :active :type :stream :remote-host host :remote-port port ;; :local-host (resolve-hostname local-host) ;; :local-port local-port :deadline deadline)) https) (unwind-protect (handler-bind ((ssl-error-verify (lambda (c) (write-ssl-certificate-names (ssl-error-stream c))))) (setf https (cl+ssl:make-ssl-client-stream socket :unwrap-stream-p t :external-format '(:iso-8859-1 :eol-style :lf))) (write-ssl-certificate-names https) (format https "GET / HTTP/1.0~%Host: ~a~%~%" host) (force-output https) (loop :for line = (read-line-crlf-2 https nil) for cnt from 0 :while line :do (when show-text-p (format t "HTTPS> ~a~%" line)) finally (return cnt))) (if https (close https) (close socket))))) (defparameter *rayservers-ca-certificate-pem-file* "rayservers-ca-certificate.pem") (defparameter *rayservers-ca-certificate-path* (merge-pathnames *rayservers-ca-certificate-pem-file* (asdf:system-source-directory :cl+ssl))) (defparameter *rayservers-ca-certificate-pem* "-----BEGIN CERTIFICATE----- MIIElTCCA32gAwIBAgIJALoXNnj+yvJCMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD VQQGEwJQQTELMAkGA1UECBMCTkExFDASBgNVBAcTC1BhbmFtYSBDaXR5MRgwFgYD VQQKEw9SYXlzZXJ2ZXJzIEdtYkgxGjAYBgNVBAMTEWNhLnJheXNlcnZlcnMuY29t MSUwIwYJKoZIhvcNAQkBFhZzdXBwb3J0QHJheXNlcnZlcnMuY29tMB4XDTA5MTAx OTE3MzgyMFoXDTE5MTAxNzE3MzgyMFowgY0xCzAJBgNVBAYTAlBBMQswCQYDVQQI EwJOQTEUMBIGA1UEBxMLUGFuYW1hIENpdHkxGDAWBgNVBAoTD1JheXNlcnZlcnMg R21iSDEaMBgGA1UEAxMRY2EucmF5c2VydmVycy5jb20xJTAjBgkqhkiG9w0BCQEW FnN1cHBvcnRAcmF5c2VydmVycy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw ggEKAoIBAQC9rNsCCM+TNp6xDk2yxhXQOStmPTd0txFyduNAj02/nLZV4eq0ZS5n xXBE6l3MYIMBMV3BgKiy7LsdiRJeZ5HdsV/HRZzXCQI+k4acBjlRC1ZdWMNsIR+H QUVx2y0wgp+QpcMrgBQZdPI7PobnXCZ6+Fmc50kM7xbIsoWZUzQDpRtUymgOhnnT 4TSb1/XufFHHhDMReRA7s3Co911hzcnZJqL9gFWULlB/RI2ZeVbkp0K4lUXyMZ/R fnOtCdAA+TkQcpzoyBETV9p5MO8KBOPBskvyGYqVcIZNuxwfC2uoKx0s5b6eMRKR 54B4mB/hIi7i0uGjzuAZdt5iDXQHYaM3AgMBAAGjgfUwgfIwHQYDVR0OBBYEFOyu Fp80LSc1gwnq5rghs/P8bMgrMIHCBgNVHSMEgbowgbeAFOyuFp80LSc1gwnq5rgh s/P8bMgroYGTpIGQMIGNMQswCQYDVQQGEwJQQTELMAkGA1UECBMCTkExFDASBgNV BAcTC1BhbmFtYSBDaXR5MRgwFgYDVQQKEw9SYXlzZXJ2ZXJzIEdtYkgxGjAYBgNV BAMTEWNhLnJheXNlcnZlcnMuY29tMSUwIwYJKoZIhvcNAQkBFhZzdXBwb3J0QHJh eXNlcnZlcnMuY29tggkAuhc2eP7K8kIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0B AQUFAAOCAQEAqScS+A2Hajjb+jTKQ19LVPzTpRYo1Jz0SPtzGO91n0efYeRJD5hV tU+57zGSlUDszARvB+sxzLdJTItK+wEpDM8pLtwUT/VPrRKOoOUBkKBshcTD4HmI k8uJlNed0QQLP41hFjr+mYd7WM+N5LtFMQAUBMUN6dzEqQIx69EnIoVp0KB8kDwW /QK5ogKY0g8DmRTFiV036bHQH93kLzyV6FNAldO8vBDqcTeru/uU2Kcn6a8YOfO1 T6MVYory7prWbBaGPKsGw0VgrV9OGbxhbw9EOEYSOgdejvbi9VhgMvEpDYFN7Hnq 0wiHJq5jKECf3bwRe9uVzVMrIeCap/r2uA== -----END CERTIFICATE-----") (defun write-rayservers-certificate-pem () (with-open-file (s *rayservers-ca-certificate-path* :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string *rayservers-ca-certificate-pem* s) *rayservers-ca-certificate-path*)) (defun install-rayservers-ca-certificate () (let ((path (write-rayservers-certificate-pem))) (ssl-load-global-verify-locations path))) (defun test-loom-client (&optional show-text-p) (test-https-client-2 "secure.loom.cc" :show-text-p show-text-p)) (defun test-yahoo-client (&optional show-text-p) (test-https-client-2 "yahoo.com" :show-text-p show-text-p)) (defmacro expecting-no-errors (&body body) `(handler-case (progn ,@body) (error (c) (error "Got an unexpected error: ~a" c)))) (defmacro expecting-error ((type) &body body) `(let ((got-error-p nil)) (handler-case (progn ,@body) (error (c) (unless (typep c ',type) (error "Got an unexpected error type: ~a" c)) (setf got-error-p t))) (unless got-error-p (error "Did not get expected error.")))) (defun test-verify (&optional quietly) (let ((*standard-output* ;; test-https-client-2 prints the certificate names (if quietly (make-broadcast-stream) *standard-output*))) (expecting-no-errors (reload) (test-loom-client) (test-yahoo-client) (setf (ssl-check-verify-p) t)) ;; The Mac appears to have no way to get rid of the default CA certificates ;; #+darwin-host is only true in Clozure Common Lisp running on a Mac, ;; So this test will fail in SBCL on a Mac #-darwin-host (expecting-error (ssl-error-verify) (test-yahoo-client)) #+darwin-host (expecting-no-errors (test-yahoo-client)) (expecting-error (ssl-error-verify) (test-loom-client)) (expecting-no-errors (install-rayservers-ca-certificate) (test-loom-client)) (expecting-no-errors (ssl-set-global-default-verify-paths) (test-yahoo-client))))
6,350
Common Lisp
.lisp
151
35.589404
79
0.704884
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
81acd467a0d9170c3a6b8cd064f9fa30ccb717cbd20262e3de27392115de272a
42,826
[ 357035, 475039 ]
42,827
run-for-ci.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/run-for-ci.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. ;;;; This script is intended to be LOAD'ed to execute tests ;;;; in the CI environment, like GitHub Actions. ;;;; ;;;; As input it accepts some environment variables, see the code. ;;;; Logs it's actions to standard output. ;;;; Exit code of the script indicates test success = 0 or failure = 1. (unless (uiop:getenvp "OPENSSL") (error "The OPENSSL environment variable is required")) (unless (uiop:getenvp "BITS") (error "The BITS environment variable is required")) (unless (uiop:getenvp "OPENSSL_RELEASES_BIN_DIR") (error "The OPENSSL_RELEASES_BIN_DIR environment variable is required")) (when (uiop:getenvp "READTABLE_CASE_INVERT") (format t "changing readtable-case to :invert~%") (setq *readtable* (let ((rt (copy-readtable))) (setf (readtable-case rt) :invert) rt))) (format t "(lisp-implementation-type): ~A~%" (lisp-implementation-type)) (format t "(lisp-implementation-version): ~A~%" (lisp-implementation-version)) (format t "*features*: ~A~%" *features*) (format t "(asdf:asdf-version): ~A~%" (asdf:asdf-version)) ;;; make sure ASDF will find the cl+ssl version from this repository (defparameter *this-dir* (make-pathname :name nil :type nil :defaults *load-truename*)) (defparameter *parent-dir* ;; Maybe getting parent dir this way is not not portable, ;; but should work for Linux. ;; TODO: probably use the portable code from cl-fad:pathname-parent-directory ;; https://github.com/edicl/cl-fad/blob/3f4d32d3aa1093966046d001411a852eb8f4b535/fad.lisp#L328 (merge-pathnames "../" *this-dir*)) (pushnew *parent-dir* asdf:*central-registry* :test #'equal) #+abcl (progn (format t "Loading abcl-asdf and switching maven repo URL to HTTPS (see https://github.com/armedbear/abcl/issues/151)~%") (require :abcl-contrib) (format t "abcl-contrib loaded...~%") (require :abcl-asdf) (format t "abcl-asdf loaded...~%") (format t "*features*: ~A~%" *features*) (setf (symbol-value (read-from-string "abcl-asdf::*default-repository*")) "https://repo1.maven.org/maven2/") (format t "abcl-asdf::*default-repository* assigned the HTTPS URL.~%")) (ql:quickload :cffi) (format t "cffi loaded.~%") (ql:quickload :cl+ssl/config) (format t "cl+ssl/config loaded.~%") (let* ((openssl (uiop:getenv "OPENSSL")) (bits (uiop:getenv "BITS")) (openssl-releases-bin-dir (uiop:getenv "OPENSSL_RELEASES_BIN_DIR")) (lib-dir (format nil "~A/~A-~Abit/lib~A" openssl-releases-bin-dir openssl bits (if (and (string= "64" bits) (search "openssl-3." openssl)) "64" "")))) (defparameter *libcrypto.so* (concatenate 'string lib-dir "/libcrypto.so")) (defparameter *libssl.so* (concatenate 'string lib-dir "/libssl.so"))) (let ((lib-load-mode (uiop:getenvp "LIB_LOAD_MODE"))) (cond ((string= "new" lib-load-mode) (cl+ssl/config:define-libcrypto-path #.*libcrypto.so*) (cl+ssl/config:define-libssl-path #.*libssl.so*)) ((string= "old" lib-load-mode) (cffi:load-foreign-library *libcrypto.so*) (format t "libcrypto.so loaded.~%") (cffi:load-foreign-library *libssl.so*) (format t "libssl.so loaded.~%") (pushnew :cl+ssl-foreign-libs-already-loaded *features*)) (t (format t "Unexpected LIB_LOAD_MODE value: ~A~%" lib-load-mode) (uiop:quit 1)))) ;;; load cl+ssl separately from cl+ssl.test only because cl+ssl.test can not be loaded in the :invert readtable-case due to its dependency ironclad, as of 2019-10-20 (format t "Loading cl+ssl from ~A~%" (asdf:system-source-file (asdf:find-system :cl+ssl))) (ql:quickload :cl+ssl) (format t "cl+ssl loaded.~%") (when (uiop:getenvp "READTABLE_CASE_INVERT") (format t "restoring readtable-case to :upcase before loading cl+ssl.test~%") (setf (readtable-case *readtable*) :upcase)) (ql:quickload :cl+ssl.test) (format t "(cl+ssl::compat-openssl-version): ~A~%" (cl+ssl::compat-openssl-version)) ;; Since we load customly built openssl libs, it may not find the path ;; to trusted root serts on our system. Let's configure this path, as ;; we have it on my Ubunto and in the CI docker image. (cl+ssl:ensure-initialized) ; needed to set the *ssl-global-context* (cl+ssl::ssl-ctx-set-verify-location cl+ssl::*ssl-global-context* "/etc/ssl/certs/") (let ((results #+ sbcl (coveralls:with-coveralls (:exclude "test") (5am:run :cl+ssl)) #- sbcl (5am:run :cl+ssl) )) (5am:explain! results) (unless (5am:results-status results) (uiop:quit 1))) (uiop:quit 0)
4,980
Common Lisp
.lisp
106
41.207547
165
0.654448
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
3ee61e6913902a49f7261b48975df5e2254bfd04b73d7232ec063827923f6b0e
42,827
[ -1 ]
42,828
package.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/package.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl-user) (defpackage :cl+ssl.test (:use :cl :5am)) (in-package :cl+ssl.test) (def-suite :cl+ssl :description "Main test suite for CL+SSL")
374
Common Lisp
.lisp
12
28.833333
111
0.673184
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
456c999c37a93d679c31959e17141d2dad0bec8c4ae787ed5b9cf04c0bacd0e1
42,828
[ -1 ]
42,829
cert-utilities.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/cert-utilities.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (defun full-cert-path (name) (merge-pathnames (concatenate 'string "test/certs/" name) (asdf:component-pathname (asdf:find-system :cl+ssl.test)))) (defun load-cert(name) (let ((full-path (full-cert-path name))) (unless (probe-file full-path) (error "Unable to find certificate ~a~%Full path: ~a" name full-path)) (cl+ssl:decode-certificate-from-file full-path))) (defmacro with-cert ((name var) &body body) `(let* ((,var (load-cert ,name))) (when (cffi:null-pointer-p ,var) (error "Unable to load certificate: ~a" ,name)) (unwind-protect (progn ,@body) (cl+ssl::x509-free ,var))))
954
Common Lisp
.lisp
23
34.347826
111
0.605178
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
874efbed59edbf12265e888857531efd421936c20be70863dcddd1d0a41d9ea6
42,829
[ -1 ]
42,830
verify-hostname.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/verify-hostname.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.verify-hostname :in :cl+ssl :description "Hostname verification tests") (in-suite :cl+ssl.verify-hostname) (test veriy-hostname-success ;; presented identifier, reference identifier, validation and parsing result (let ((tests '(("www.example.com" "WWW.eXamPle.CoM" (nil)) ;; case insensitive match ("www.example.com." "www.example.com" (nil)) ;; ignore trailing dots (prevenet *.com. matches) ("www.example.com" "www.example.com." (nil)) ("*.example.com" "www.example.com" (t "" ".example.com" t)) ("b*z.example.com" "buzz.example.com" (t "b" "z.example.com" nil)) ("*baz.example.com" "foobaz.example.com" (t "" "baz.example.com" nil)) ("baz*.example.com" "baz1.example.com" (t "baz" ".example.com" nil))))) (loop for (i r v) in tests do (is (equalp (multiple-value-list (cl+ssl::validate-and-parse-wildcard-identifier i r)) v)) (is (cl+ssl::try-match-hostname i r))))) (test verify-hostname-fail (let ((tests '(("*.com" "eXamPle.CoM") (".com." "example.com.") ("*.www.example.com" "www.example.com.") ("foo.*.example.com" "foo.bar.example.com.") ("xn--*.example.com" "xn-foobar.example.com") ("*fooxn--bar.example.com" "bazfooxn--bar.example.com") ("*.akamaized.net" "tv.eurosport.com") ("a*c.example.com" "abcd.example.com") ("*baz.example.com" "foobuzz.example.com")))) (loop for (i r) in tests do (is-false (cl+ssl::try-match-hostname i r))))) (test verify-google-cert (with-cert ("google.der" cert) (is-true (cl+ssl:verify-hostname cert "qwe.fr.doubleclick.net")))) (test verify-google-cert-dns-wildcard (with-cert ("google_wildcard.der" cert) (is-true (cl+ssl:verify-hostname cert "www.google.co.uk")))) (test verify-google-cert-without-dns (with-cert ("google_nodns.der" cert) (is-true (cl+ssl:verify-hostname cert "www.google.co.uk")))) (test verify-google-cert-printable-string (with-cert ("google_printable.der" cert) (is-true (cl+ssl:verify-hostname cert "www.google.co.uk")))) (test verify-google-cert-teletex-string (with-cert ("google_teletex.der" cert) (is-true (cl+ssl:verify-hostname cert "www.google.co.uk")))) (test verify-google-cert-bmp-string (with-cert ("google_bmp.der" cert) (is-true (cl+ssl:verify-hostname cert "google.co.uk")))) (test verify-google-cert-universal-string (with-cert ("google_universal.der" cert) (is-true (cl+ssl:verify-hostname cert "google.co.uk")))) (test verify-alt-names-wildcard (with-cert ("google.der" cert) (is-true (cl+ssl:verify-hostname cert "foobarbaz.android.com")))) (test verify-IP-check (with-cert ("localhost.der" cert) (print (cl+ssl::certificate-dns-alt-names cert)) (is-true (cl+ssl:verify-hostname cert "127.0.0.1")) (is-true (cl+ssl:verify-hostname cert "::1")) (is-true (cl+ssl:verify-hostname cert "localhost"))))
3,746
Common Lisp
.lisp
74
38.648649
111
0.559595
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a6aba65d73dcb014529085e020a3a6dc4ac02cedaeb64dc56f0d369780b67088
42,830
[ -1 ]
42,831
fingerprint.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/fingerprint.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.fingerprint :in :cl+ssl :description "Certificate fingerprint test") (in-suite :cl+ssl.fingerprint) (test fingerprint-google-cert (with-cert ("google.der" cert) (is (equalp (cl+ssl:certificate-fingerprint cert) #(#x7F #xD0 #x53 #xFA #x7F #x4E #x6E #x20 #xDA #xD4 #xC1 #x26 #x2A #x54 #x57 #x82 #xA2 #x22 #xA0 #xBC))) (is (equalp (cl+ssl:certificate-fingerprint cert :md5) #(#x67 #xAC #xDC #xE3 #x51 #x60 #x44 #x9A #xCB #x2A #x64 #x89 #xA9 #x10 #x52 #x39)))))
793
Common Lisp
.lisp
17
40.705882
111
0.621762
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
787ba42cc5e23ec10e31498ef5a5bb830866dd6089254c345c19d726a9d6c0d4
42,831
[ -1 ]
42,832
alpn.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/alpn.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.alpn :in :cl+ssl :description "ALPN tests") (in-suite :cl+ssl.alpn) (test alpn-client (when (cl+ssl::openssl-is-at-least 1 0 2) (flet ((test-alpn-result (target proposed expected) (usocket:with-client-socket (socket stream target 443 :element-type '(unsigned-byte 8)) (is (equal expected (cl+ssl:get-selected-alpn-protocol (cl+ssl:make-ssl-client-stream stream :alpn-protocols proposed))))))) (test-alpn-result "example.com" nil nil) (test-alpn-result "example.com" '( "should-not-exist" "h2" "also-should-not-exist") "h2"))))
966
Common Lisp
.lisp
21
36.047619
111
0.582359
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
2c507878a94b9d74ee30c562762267eab97f3f04877a615aa0edd465ac15046a
42,832
[ -1 ]
42,833
badssl-com.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/badssl-com.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.badssl-com :in :cl+ssl :description "Tests using badssl.com") (in-suite :cl+ssl.badssl-com) (defun test-connect (host &key (verify :required)) (usocket:with-client-socket (socket stream host 443 :element-type '(unsigned-byte 8)) (cl+ssl:make-ssl-client-stream stream :hostname host :verify verify))) (defmacro modal-test (name &body body) "Defines two tests, with equal body, but first executed using file descriptor BIO, and the other executed with Lisp BIO." `(progn (test ,(read-from-string (format nil "~A.file-descriptor-bio" name)) (let ((cl+ssl::*default-unwrap-stream-p* t)) ,@body)) (test ,(read-from-string (format nil "~A.lisp-bio" name)) (let ((cl+ssl::*default-unwrap-stream-p* nil)) ,@body)))) (modal-test wrong.host (signals error (test-connect "wrong.host.badssl.com")) (signals error (test-connect "wrong.host.badssl.com" :verify :optional)) (finishes (test-connect "wrong.host.badssl.com" :verify nil))) (modal-test expired (signals error (test-connect "expired.badssl.com")) (signals error (test-connect "expired.badssl.com" :verify :optional)) (finishes (test-connect "expired.badssl.com" :verify nil))) (modal-test self-signed (signals error (test-connect "self-signed.badssl.com"))) (modal-test untrusted-root (signals error (test-connect "untrusted-root.badssl.com")))
1,763
Common Lisp
.lisp
45
33.288889
111
0.653981
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
6c58030ecbd9681a05410827cc3687393f79be16b3ab17f417b0ec35eed71f4e
42,833
[ -1 ]
42,834
sni.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/sni.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.sni :in :cl+ssl :description "Server Name Indications tests") (in-suite :cl+ssl.sni) (defun make-request-to-sni-test-server (sni-enabled) (usocket:with-client-socket (socket stream "sni.velox.ch" 443 :element-type '(unsigned-byte 8)) (let* ((ssl-stream (cl+ssl:make-ssl-client-stream stream :hostname (if sni-enabled "sni.velox.ch"))) (char-stream (flexi-streams:make-flexi-stream ssl-stream :external-format '(:utf-8 :eol-style :crlf))) (reply-buf (make-string 1000))) (unwind-protect (progn (format char-stream "GET / HTTP/1.1~%") (format char-stream "Host: sni.velox.ch~%~%") (finish-output char-stream) (read-sequence reply-buf char-stream) reply-buf) (close ssl-stream))))) (defun sni-test-request-succeeded-p (response) (search "Great!" response)) (defun sni-test-request-failed-p (response) (search "Unfortunately" response)) ;; Disable the SNI tests because sni.velox.ch was shut down and we ;; haven't found a replacement. ;; ;; (test (sni.disabled :compile-at :definition-time) ;; (is-true (sni-test-request-failed-p (make-request-to-sni-test-server nil)) ;; "Request to SNI test server should've failed because SNI was disabled")) ;; ;; (test (sni.enabled :compile-at :definition-time) ;; (is-true (sni-test-request-succeeded-p (make-request-to-sni-test-server t)) ;; "Request to SNI test server should've succeseeded because SNI was enabled"))
1,913
Common Lisp
.lisp
39
40.871795
111
0.619175
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
6d2c49e958c6aa5e8810d2eebbf723e1557364e4b38b5a7514cc6cdea39ebe61
42,834
[ -1 ]
42,835
version.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/version.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (in-suite :cl+ssl) (test compat-openssl-version (is-true (integerp (cl+ssl::compat-openssl-version))))
340
Common Lisp
.lisp
9
36.222222
111
0.698171
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
c63b56ae992e5e52d2e226db7fd7f6e112139d8713f66c9888308083dfbb8ce6
42,835
[ -1 ]
42,836
validity-dates.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/validity-dates.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.validity-dates :in :cl+ssl :description "Validity date tests") (in-suite :cl+ssl.validity-dates) (test validity-dates-google-cert (when (and (cl+ssl::openssl-is-at-least 1 1 0) (not (cl+ssl::libresslp))) (with-cert ("google.der" cert) (is (= (cl+ssl:certificate-not-after-time cert) 3641760000)) (is (= (cl+ssl:certificate-not-before-time cert) 3634055286))))) (test validity-dates-after-2050 "Make sure we handle dates after 2050, which are encoded in ASN1 as a GeneralizedTime, whereas dates before 2050 are encoded as UTCTime." (when (and (cl+ssl::openssl-is-at-least 1 1 0) (not (cl+ssl::libresslp))) (with-cert ("mixed-time-formats.der" cert) (is (= (cl+ssl:certificate-not-before-time cert) (encode-universal-time 04 25 11 20 11 2021 0))) (is (= (cl+ssl:certificate-not-after-time cert) (encode-universal-time 04 25 11 20 11 2071 0))))))
1,220
Common Lisp
.lisp
27
39.62963
111
0.65404
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5757e7ee8fdcc2cbeae0610ef3fd83eb6b72f13074da1ec59ce0f5d1b3143eda
42,836
[ -1 ]
42,837
bio.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/bio.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2021 Tomas Zellerin ([email protected], https://github.com/zellerin) ;;; Copyright (C) 2021 Anton Vodonosov ([email protected], https://github.com/avodonosov) ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (def-suite :cl+ssl.bio :in :cl+ssl :description "Bio interface test") (in-suite :cl+ssl.bio) (cl+ssl::define-crypto-function ("BIO_write" bio-write) :int (bio :pointer) (text :string) (len :int)) (cl+ssl::define-crypto-function ("BIO_read" bio-read) :int (bio :pointer) (text :pointer) (len :int)) (cl+ssl::define-crypto-function ("BIO_gets" bio-gets) :int (bio :pointer) (text :pointer) (len :int)) (cl+ssl::define-crypto-function ("BIO_puts" bio-puts) :int (bio :pointer) (text :string)) (test bio-read (is (equalp '("Hel" "lo") (cl+ssl::with-bio-input-from-string (bio "Hello") (cffi:with-foreign-object (array :char 32) (flet ((bio-read-to-string (len) (let ((size (bio-read bio array len))) (assert (< size 31)) (setf (cffi:mem-ref array :unsigned-char size) 0) (cffi:foreign-string-to-lisp array)))) (list (bio-read-to-string 3) (bio-read-to-string 32)))))))) (test bio-gets (cffi:with-foreign-object (array :char 32) (is (equalp '(6 "Hello " 3 "bar") (cl+ssl::with-bio-input-from-string (bio "Hello bar") (list (bio-gets bio array 32) (cffi:foreign-string-to-lisp array) (bio-gets bio array 32) (cffi:foreign-string-to-lisp array))) )) ;; check that the array is zero terminated ;; and thus the max number of chars read is len - 1. (setf (cffi:mem-ref array :unsigned-char 4) 7) ; will be replaced by zero terminator (is (= 4 (cl+ssl::with-bio-input-from-string (bio "1234567") (bio-gets bio array 5)))) (is (= 0 (cffi:mem-ref array :unsigned-char 4))) ;; when the len 0, the return value is 0, and the array is still (setf (cffi:mem-ref array :unsigned-char 0) 7) ; will be replaced by zero terminator (is (= 0 (cl+ssl::with-bio-input-from-string (bio "zzz") (bio-gets bio array 0)))) (is (= 0 (cffi:mem-ref array :unsigned-char 0))))) (test bio-write-puts (is (equalp "Hello Hi Hallo" (cl+ssl::with-bio-output-to-string (bio) (bio-write bio #1="Hello " (length #1#)) (bio-puts bio "Hi") (bio-write bio #2="Hallo" (length #2#))))))
2,765
Common Lisp
.lisp
75
30.426667
111
0.598954
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
245e59b04d75034668fb8e21342cf28bdfa8b009d2668d2cd6756696e1eb9217
42,837
[ -1 ]
42,838
dummy.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/dummy.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl.test) (in-suite :cl+ssl) (test (sanity-check.1 :compile-at :definition-time) (is-true t "SANITY CHECK: T isn't T")) (test (sanity-check.2 :compile-at :definition-time) (is-false nil "SANITY CHECK: NIL isn't NIL"))
448
Common Lisp
.lisp
11
39
111
0.690531
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
7956a1e7bb4044e230a3b89d5112429f0f8af150c92ddee16010816489415b93
42,838
[ -1 ]
42,839
run-home.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/run-on-many-lisps-and-openssls/run-home.lisp
(defparameter *this-dir* (if *load-truename* (make-pathname :name nil :type nil :defaults *load-truename*) ;; for slime: #P"/home/anton/prj/cl+ssl/cl-plus-ssl/test/run-on-many-lisps-and-openssls/")) (load (merge-pathnames "run-on-many-lisps-and-openssls.lisp" *this-dir*)) (defparameter *abcl-1.3.1* (make-instance 'lisp-exe:abcl :java-exe-path "java" :abcl-jar-path "/home/anton/unpacked/abcl-bin-1.3.1/abcl.jar")) (defparameter *ccl-1.11-x86-64* (make-instance 'lisp-exe:ccl :exe-path "/home/anton/unpacked/ccl-1.11/lx86cl64")) (defparameter *sbcl-1.4.13* (make-instance 'lisp-exe:sbcl :exe-path "/home/anton/unpacked/sbcl-1.4.13-x86-64-linux/run-sbcl.sh")) ;; (run-on-many-lisps-and-openssls:clean-fasls (merge-pathnames "workdir/" *this-dir*)) (let ((*print-pretty* t)) (format t "~S~%" (time (run-on-many-lisps-and-openssls:run :test-run-description '(:lib-world "quicklisp 2019-01-07 + cl+ssl.head" :contact-email "[email protected]") :test-run-dir (merge-pathnames "workdir/" *this-dir*) :quicklisp-dir (merge-pathnames "quicklisp/" (user-homedir-pathname)) ;; :cl+ssl-location (uiop:pathname-parent-directory-pathname ;; (uiop:pathname-parent-directory-pathname *this-dir*)) :cl+ssl-location nil ;; to use the cl+ssl version from quicklisp :lisps (list *ccl-1.11-x86-64* *sbcl-1.4.13* *abcl-1.3.1* ) :openssl-releases '("openssl-0.9.8zh" ; "openssl-1.0.0s" ; "openssl-1.0.2q" ; "openssl-1.1.0j" ; "openssl-1.1.1a" ) :openssl-releases-dir (merge-pathnames "openssl-releases/bin/" *this-dir*)))))
2,211
Common Lisp
.lisp
37
40.216216
114
0.49377
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
cbdea6c3ab021bc756e662bb8663426bb80c4b98f3f18bf46ebd95902d7ae5fb
42,839
[ 210222 ]
42,840
run-on-many-lisps-and-openssls.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/run-on-many-lisps-and-openssls/run-on-many-lisps-and-openssls.lisp
(ql:quickload :test-grid-agent) (ql:quickload :test-grid-utils) (ql:quickload :cl-fad) (ql:quickload :alexandria) (ql:quickload :log4cl) (defpackage #:run-on-many-lisps-and-openssls (:use :common-lisp) (:export #:run #:clean-fasls)) (in-package :run-on-many-lisps-and-openssls) (defun fasl-root (test-run-dir) (merge-pathnames "fasl/" test-run-dir)) (defun sanitize-as-path (str) ;; Substitute dots by hypens if our main process is CCL, it ;; prepends the > symbol before dots; ;; for example: 1.1.0.36.mswinmt.1201-284e340 => 1>.1>.0>.36>.mswinmt.1201-284e340 ;; When we pass such a pathname to other lisps, they can't handle it. (substitute #\- #\. str)) (defun log-name (lisp openssl-release) (sanitize-as-path (string-downcase (concatenate 'string (tg-agent::implementation-identifier lisp) "-" openssl-release)))) (defun fasl-dir (test-run-dir lisp) (merge-pathnames (format nil "~(~A~)/" (sanitize-as-path (tg-agent::implementation-identifier lisp))) (fasl-root test-run-dir))) (defun so-path (openssl-releases-dir openssl-release so-name) (merge-pathnames (format nil "~A/lib/~A" openssl-release so-name) openssl-releases-dir)) (defun run (&key test-run-description test-run-dir quicklisp-dir lisps openssl-releases openssl-releases-dir cl+ssl-location) ;; (unless cl+ssl-location ;; (error "cl+ssl-location parameter is not specified and *load-truename* was not available at the load time.")) (ensure-directories-exist test-run-dir) (let ((lisp-exe:*temp-dir* test-run-dir)) (flet ((run-lib-test (lisp openssl-release) (tg-agent::proc-run-libtest lisp :cl+ssl (cons :lisp (cons (tg-agent::implementation-identifier lisp) test-run-description)) (merge-pathnames (log-name lisp openssl-release) test-run-dir) quicklisp-dir (fasl-dir test-run-dir lisp) :eval-before-test `(progn (set (read-from-string "asdf:*central-registry*") (cons ,cl+ssl-location (symbol-value (read-from-string "asdf:*central-registry*")))) ,(when cl+ssl-location `(cl-user::fncall "add-asdf-output-translation" ,cl+ssl-location ,(merge-pathnames "cl+ssl/" (fasl-dir test-run-dir lisp)))) (cl-user::fncall "ql:quickload" :cffi) (cl-user::fncall "cffi:load-foreign-library" ,(so-path openssl-releases-dir openssl-release "libcrypto.so")) (cl-user::fncall "cffi:load-foreign-library" ,(so-path openssl-releases-dir openssl-release "libssl.so")) (pushnew :cl+ssl-foreign-libs-already-loaded *features*))))) (tg-utils::write-to-file (alexandria:map-product (lambda (lisp openssl-release) (list (tg-agent::implementation-identifier lisp) openssl-release (getf (run-lib-test lisp openssl-release) :status))) lisps openssl-releases) (merge-pathnames "results.lisp" test-run-dir))))) (defun clean-fasls (test-run-dir) (cl-fad:delete-directory-and-files (fasl-root test-run-dir)))
3,990
Common Lisp
.lisp
78
34.282051
119
0.521159
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
7e4ff74b38ffb66619cdcd2e47cabbf3dbe83a523c2bf37a2ae4530832fcefea
42,840
[ 385688 ]
42,841
run-on-server.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/test/run-on-many-lisps-and-openssls/run-on-server.lisp
(defparameter *this-dir* (if *load-truename* (make-pathname :name nil :type nil :defaults *load-truename*) ;; for slime: #P"/home/testgrid/cl+ssl/cl-plus-ssl/test/run-on-many-lisps-and-openssls/")) (pushnew "/home/testgrid/cl-test-grid/" asdf:*central-registry* :test #'equal) (load (merge-pathnames "run-on-many-lisps-and-openssls.lisp" *this-dir*)) (defparameter *abcl-1.5.0* (make-instance 'lisp-exe:abcl :java-exe-path "java" :abcl-jar-path "/home/testgrid/lisps/abcl-bin-1.5.0/abcl.jar")) (defparameter *acl-10.0* (make-instance 'lisp-exe:acl :exe-path "/home/testgrid/lisps/acl100/alisp")) (defparameter *acl-10.0m* (make-instance 'lisp-exe:acl :exe-path "/home/testgrid/lisps/acl100/mlisp")) (defparameter *acl-10.0-smp* (make-instance 'lisp-exe:acl :exe-path "/home/testgrid/lisps/acl100-smp/alisp")) (defparameter *acl-10.0m-smp* (make-instance 'lisp-exe:acl :exe-path "/home/testgrid/lisps/acl100-smp/mlisp")) (defparameter *ccl-1.11.5* (make-instance 'lisp-exe:ccl :exe-path "/home/testgrid/lisps/ccl-1.11.5/lx86cl")) (defparameter *sbcl-1.3.21* (make-instance 'lisp-exe:sbcl :exe-path "/home/testgrid/lisps/sbcl-bin-1.3.21/run.sh")) (defparameter *cmucl-2016-12* (make-instance 'lisp-exe:cmucl :exe-path "/home/testgrid/lisps/cmucl-2016-12/bin/lisp")) (defparameter *cmucl-2016-12* (make-instance 'lisp-exe:cmucl :exe-path "/home/testgrid/lisps/cmucl-2016-12/bin/lisp")) (defparameter *cmucl-21d* (make-instance 'lisp-exe:cmucl :exe-path "/home/testgrid/lisps/cmucl-21d/bin/lisp")) (defparameter *ecl-16.1.2-bytecode* (make-instance 'lisp-exe:ecl :exe-path "/home/testgrid/lisps/ecl-bin-16.1.2/bin/ecl" :compiler :bytecode)) (defparameter *ecl-16.1.2-lisp-to-c* (make-instance 'lisp-exe:ecl :exe-path "/home/testgrid/lisps/ecl-bin-16.1.2/bin/ecl" :compiler :lisp-to-c)) (defparameter *clisp* (make-instance 'lisp-exe:clisp :exe-path "/usr/bin/clisp")) (run-on-many-lisps-and-openssls:clean-fasls (merge-pathnames "workdir/" *this-dir*)) (let ((*print-pretty* t)) (format t "~%~S~%" (time (run-on-many-lisps-and-openssls:run :test-run-description '(:lib-world "quicklisp 2019-01-07 + cl+ssl.head" :contact-email "[email protected]") :test-run-dir (merge-pathnames "workdir/" *this-dir*) :quicklisp-dir (merge-pathnames "quicklisp/" (user-homedir-pathname)) ;; if we want the cl+ssl from the parent folder :cl+ssl-location (uiop:pathname-parent-directory-pathname (uiop:pathname-parent-directory-pathname *this-dir*)) ;; if we want the cl+ssl version from quicklisp ;:cl+ssl-location nil :lisps (list *sbcl-1.3.21* *ccl-1.11.5* *abcl-1.5.0* *acl-10.0* *acl-10.0m* *acl-10.0-smp* *acl-10.0m-smp* *clisp* *ecl-16.1.2-bytecode* *ecl-16.1.2-lisp-to-c* *cmucl-21d* ) :openssl-releases '("openssl-0.9.8zh" "openssl-1.0.0s" "openssl-1.0.2q" "openssl-1.1.0j" "openssl-1.1.1a" ) :openssl-releases-dir (merge-pathnames "openssl-releases/bin/" *this-dir*)))))
3,806
Common Lisp
.lisp
79
35.240506
84
0.556125
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
304d3b2d947ed7413e89f649622908eeff3805eaceda1f34304b6320b8332eb2
42,841
[ 46238 ]
42,842
client-certificates-example-static.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/examples/client-certificates-example-static.lisp
;;;; The code contained in this file implements a trivial server and a ;;;; client that connects to the former and provide a self signed ;;;; certificate. The server is able to implement a procedure to ;;;; reject or accept the client connection, based on the client's ;;;; certificate, and using some form of authentication. For example ;;;; matching the certificate fingerprint with a database of ;;;; certificates stored on disk, for example. ;; To generate both the keys and certificates, a command line like the ;; one below could be used: ;; openssl req -new -nodes -x509 -days 365 -subj / -keyout private-key -outform PEM -out certificate ;; The key points here are: ;; For the server ;; - create a context using :verify-mode cl+ssl:+ssl-verify-peer+ ;; Optional only if you plan to use self signed client certificates ;; - save all the trusted client's certificates in a directory of the ;; server's filesystem (for example: "/certs/trusted-clients/") ; ;; - generate symbolic links to such certificates using this command ;; # cd /certs/trusted-clients && c_rehash . ;; the step above is needed by libssl to match the certificate sent by ;; the client with one of those saved on the filesystem, idf this ;; matching fails the connection is rejected. ;; For the client ;; - pass certificate and key when generating the stream as you did ;; for the server (ql:quickload "cl+ssl") (ql:quickload "bordeaux-threads") (ql:quickload "trivial-sockets") (defun hash-array->string (array) (let ((res "")) (loop for i across array do (setf res (concatenate 'string res (format nil "~2,'0x" i)))) res)) (defun start-trivial-server (port certificate key &optional (client-certificates-directory :default)) "Start a trivial server listening on `PORT' using the certificate and key stored in the file pointed by the filesystem path `CERTIFICATE' and `KEY' respectively. The argument `CLIENT-CERTIFICATES-DIRECTORY' could be either a filesystem directory containing the list of trusted client certificates or any legal value for `CL+SSL:MAKE-CONTEXT'. If the client certificates are self signed the aforementioned directory must be passed as value for argument `CLIENT-CERTIFICATES-DIRECTORY'." (format t "~&SSL server listening on port ~d~%" port) (bt:make-thread (lambda () (trivial-sockets:with-server (server (:port port)) (let* ((socket (trivial-sockets:accept-connection server :element-type '(unsigned-byte 8))) (ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-peer+ :verify-location client-certificates-directory))) (cl+ssl:with-global-context (ctx :auto-free-p t) (let* ((client-stream (cl+ssl:make-ssl-server-stream socket :external-format nil :certificate certificate :key key)) (client-certificate (cl+ssl:ssl-stream-x509-certificate client-stream)) (client-cert-fingerprint (cl+ssl:certificate-fingerprint client-certificate :sha256))) (let ((data (make-list 2))) (read-sequence data client-stream) (format t "Server got from client (identified by ~s): ~s~%" (hash-array->string client-cert-fingerprint) (coerce (mapcar #'code-char data) 'string)) (cl+ssl:x509-free client-certificate) (close socket))))))))) (defun start-trivial-client (host port data certificate key) "Start a client to connect with the server as specified by `HOST' and `PORT', sending the first two characters of the data string: `DATA' and using the certificate and key stored in the file pointed by the filesystem path `CERTIFICATE' and `KEY' respectively" (let ((ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+))) (cl+ssl:with-global-context (ctx :auto-free-p t) (let* ((stream (trivial-sockets:open-stream host port)) (ssl-stream (cl+ssl:make-ssl-client-stream stream :certificate certificate :key key :external-format nil :unwrap-stream-p t :verify nil :hostname host))) (format t "sending ~a~%" data) (write-sequence (map 'vector #'char-code data) ssl-stream) (finish-output ssl-stream) (close stream)))))
5,173
Common Lisp
.lisp
90
43.611111
100
0.580932
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
d49c54eeb3a816edb35962fe5c9755ed86cd04fc2f6bccdaf19c00b3c39ccc3c
42,842
[ -1 ]
42,843
example.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/examples/example.lisp
;;; Copyright (C) 2001, 2003 Eric Marsden ;;; Copyright (C) 2005 David Lichteblau ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt." ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #| ;; Assuming Quicklisp is installed. (load "example.lisp") (tls-example::test-https-client "www.google.com") ;; generate key and cert as explained in the test-https-server comments (tls-example::test-https-server :cert-chain-file "/path/to/certificate.pem" :key-file "/path/to/private-key.pem" :key-password "1234") ;; test the server with curl or web browser as explained in the comments (tls-example::test-nntp-client) |# (defpackage :tls-example (:use :cl)) (in-package :tls-example) (eval-when (:compile-toplevel :load-toplevel :execute) (ql:quickload '("cl+ssl" "trivial-sockets" "usocket"))) ;; Open an HTTPS connection to a secure web server and make a ;; HEAD request (defun test-https-client (host &optional (port 443)) (let* ((deadline (+ (get-internal-real-time) (* 3 internal-time-units-per-second))) (socket (usocket:socket-connect host port :element-type '(unsigned-byte 8) #+ccl :deadline #+ccl deadline)) (https (progn (cl+ssl:make-ssl-client-stream (usocket:socket-stream socket) :hostname host :external-format '(:utf-8 :eol-style :crlf))))) #-ccl (declare (ignore deadline)) (unwind-protect (progn (format https "HEAD / HTTP/1.0~%Host: ~a~%~%" host) (force-output https) (loop :for line = (read-line https nil) :while line :do (format t "HTTPS> ~a~%" line) :while (plusp (length line)) ;; Empty line means headers ended. ;; (Don't try to read further expecting end of stream, ;; because some servers, like google.com, ;; close the TCP socket without sending TLS close_notify alert, ;; and OpenSSL in this case signals an "Unexpected EOF" ;; error if we try to read. ;; Such servers expect HTTP clients to use the HTTP ;; protocol format to determine how many bytes to read, ;; instead of relying on the connection termination.) )) (close https)))) ;; Start a simple HTTPS server. ;; ;; Simple self-signed certificate and private key encrypted with ;; passphrase "1234" can be generated with ;; ;; openssl req -new -x509 -days 365 -subj / -keyout private-key.pem -passout pass:1234 -out certificate.pem -outform PEM ;; ;; For "real" certificates, you can use, for exammple, https://letsencrypt.org, ;; or see the mod_ssl documentation at <URL:http://www.modssl.org/> ;; (like http://www.modssl.org/docs/2.8/ssl_faq.html) ;; ;; Query the server: ;; ;; curl --insecure https://localhost:8080/foobar ;; ;; Stop the server: ;; ;; curl --insecure https://localhost:8080/quit ;; ;; (the --insecure is for self-signed certificate) ;; ;; If you query this server started with a self-signed certificate ;; from browser, first time the browser will show a "Security Risk" ;; error page and the server will break with "bad certificate alert" ;; error. Then you can add a browser security exception ;; from the "Security Risk" page, start the server again and re-open the URL. (defun test-https-server (&key (port 8080) (cert-chain-file "certificate.pem") (key-file "private-key.pem") (key-password "1234")) (let ((ctx (cl+ssl:make-context :certificate-chain-file cert-chain-file :private-key-file key-file :private-key-password key-password))) (unwind-protect (trivial-sockets:with-server (server (:port port)) (format t "~&SSL server listening on port ~d~%" port) (loop (let* ((socket (trivial-sockets:accept-connection server :element-type '(unsigned-byte 8))) (client (cl+ssl:with-global-context (ctx) (cl+ssl:make-ssl-server-stream socket :external-format '(:utf-8 :eol-style :crlf)))) (quit nil)) (unwind-protect (progn ;; Read and log the request with its headers (loop :for line = (read-line client nil) :while line :do (format t "HTTPS> ~a~%" line) (when (search "/quit" line) (setf quit t)) :while (plusp (length line))) ;; Write a response (format client "HTTP/1.0 200 OK~%") (format client "Server: cl+ssl/examples/example.lisp~%") (format client "Content-Type: text/plain~%") (terpri client) (format client "~:[G'day~;Bye~] at ~A!~%" quit (multiple-value-list (get-decoded-time))) (format client "CL+SSL running in ~A ~A~%" (lisp-implementation-type) (lisp-implementation-version)) (when quit (return))) (close client)))))) (cl+ssl:ssl-ctx-free ctx))) ;; Connect to an NNTP server, upgrade connection to TLS ;; using the STARTTLS command, then execute the HELP ;; command. Log the server responses. ;; ;; (We use STARTTLS instead of connecting to a dedicated ;; TLS port, becuase Gmane does not seem to have a dedicated ;; TLS port). (defun test-nntps-client (&optional (host "news.gmane.io") (port 119)) (let* ((sock (trivial-sockets:open-stream host port :element-type '(unsigned-byte 8))) (plain-text (flex:make-flexi-stream sock :external-format '(:utf-8 :eol-style :crlf)))) (format t "NNTPS> ~A~%" (read-line plain-text)) (format sock "STARTTLS~%") (force-output sock) ;; In this example we don't look at the server ;; respone line to the STARTLS command, ;; assuming it is successfull (status code 382); ;; just log it and start TLS session. (format t "NNTPS> ~A~%" (read-line plain-text)) (let ((nntps (cl+ssl:make-ssl-client-stream sock :hostname host :external-format '(:utf-8 :eol-style :crlf)))) (write-line "HELP" nntps) (force-output nntps) (loop :for line = (read-line nntps nil) :while line :do (format t "NNTPS> ~A~%" line) :until (string-equal "." line)))))
7,251
Common Lisp
.lisp
158
33.493671
124
0.547945
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a0f76cb7f50129cd28d9641f70db5e7593c2f7840fd42a4475ee7d213f08d877
42,843
[ -1 ]
42,844
client-certificates-example.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/examples/client-certificates-example.lisp
;;;; The code contained in this file implements a trivial server and a ;;;; client that connects to the former and provide a self signed ;;;; certificate. The server is able to implement a procedure to ;;;; reject or accept the client connection, based on the client's ;;;; certificate, and using some form of authentication. For example ;;;; matching the certificate fingerprint with a database of ;;;; certificates stored on disk, for example. ;;;; Also, if the certificates are used just for univocal ;;;; identification of the client, the hash of the certificate can be ;;;; saved by the server the first time the client connect and ;;;; recalled the other times with a mechanism similar to HTTP ;;;; cookies. ;; To generate both the keys and certificates, a command line like the ;; one below could be used: ;; openssl req -new -nodes -x509 -days 365 -subj / -keyout private-key -outform PEM -out certificate ;; The key points here are: ;; For the server ;; - create a context using :verify-mode cl+ssl:+ssl-verify-peer+ ;; Optional only if you plan to use self signed client certificates ;; - write a CFFI callback that always return 1 (one) to bypass the ;; certificate authentication against a certification authority; pass ;; the symbol of this callback to key parameter :verify when ;; generating the context ;; For the client ;; - pass certificate and key when generating the stream as you did ;; for the server (ql:quickload "cl+ssl") (ql:quickload "bordeaux-threads") (ql:quickload "trivial-sockets") (cffi:defcallback no-verify :int ((preverify-ok :int) (x509-store-ctx :pointer)) (declare (ignore preverify-ok x509-store-ctx)) 1) (defun hash-array->string (array) (let ((res "")) (loop for i across array do (setf res (concatenate 'string res (format nil "~2,'0x" i)))) res)) (defun start-trivial-server (port certificate key) "Start a trivial server listening on `PORT' using the certificate and key stored in the file pointed by the filesystem path `CERTIFICATE' and `KEY' respectively" (format t "~&SSL server listening on port ~d~%" port) (bt:make-thread (lambda () (trivial-sockets:with-server (server (:port port)) (let* ((socket (trivial-sockets:accept-connection server :element-type '(unsigned-byte 8))) (ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-peer+ :verify-callback 'no-verify))) (cl+ssl:with-global-context (ctx :auto-free-p t) (let* ((client-stream (cl+ssl:make-ssl-server-stream socket :external-format nil :certificate certificate :key key)) (client-certificate (cl+ssl:ssl-stream-x509-certificate client-stream)) (client-cert-fingerprint (cl+ssl:certificate-fingerprint client-certificate :sha256))) (let ((data (make-list 2))) (read-sequence data client-stream) (format t "Server got from client (identified by ~s): ~s~%" (hash-array->string client-cert-fingerprint) (coerce (mapcar #'code-char data) 'string)) (cl+ssl:x509-free client-certificate) (close socket))))))))) (defun start-trivial-client (host port data certificate key) "Start a client to connect with the server as specified by `HOST' and `PORT', sending the first two characters of the data string: `DATA' and using the certificate and key stored in the file pointed by the filesystem path `CERTIFICATE' and `KEY' respectively" (let ((ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+))) (cl+ssl:with-global-context (ctx :auto-free-p t) (let* ((stream (trivial-sockets:open-stream host port)) (ssl-stream (cl+ssl:make-ssl-client-stream stream :certificate certificate :key key :external-format nil :unwrap-stream-p t :verify nil :hostname host))) (format t "sending ~a~%" data) (write-sequence (map 'vector #'char-code data) ssl-stream) (finish-output ssl-stream) (close stream)))))
4,996
Common Lisp
.lisp
88
42.886364
100
0.564302
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
12c2f5d058d56ff4d8fe5a653cbc86b196fce9520a3e966084ccd00e1b256acf
42,844
[ -1 ]
42,845
random.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/random.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package" "conditions" "ffi" (:cond ((:featurep :clisp) "ffi-buffer-clisp") (t "ffi-buffer")) "ffi-buffer-all"))) (in-package :cl+ssl) (defun random-bytes (count) "Generates COUNT cryptographically strong pseudo-random bytes. Returns the bytes as a SIMPLE-ARRAY with ELEMENT-TYPE '(UNSIGNED-BYTE 8). Signals an ERROR in case of problems, for example when the OpenSSL random number generator has not been seeded with enough randomness to ensure an unpredictable byte sequence." (let* ((result (make-array count :element-type '(unsigned-byte 8))) (buf (make-buffer count)) (ret (with-pointer-to-vector-data (ptr buf) (rand-bytes ptr count)))) (when (/= 1 ret) (error "RANDOM-BYTES failed: error reported by the OpenSSL RAND_bytes function. ~A." (format-ssl-error-queue nil (read-ssl-error-queue)))) (s/b-replace result buf))) ;; TODO: Should we define random-specific constants and condition classes for ;; RAND_F_RAND_GET_RAND_METHOD, RAND_F_SSLEAY_RAND_BYTES, RAND_R_PRNG_NOT_SEEDED ;; (defined in the rand.h file of the OpenSSl sources)? ;; Where to place these constants/condtitions, here or in the conditions.lisp? ;; On the other hand, those constants are just numbers defined for C, ;; for now we jsut report human readable strings, without possibility ;; to distinguish these error causes programmatically.
1,700
Common Lisp
.lisp
33
45.909091
111
0.687312
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
867ab7215817d09e0edcda2ce9af31a3666018b14331fabfcbe27072dc359d1f
42,845
[ -1 ]
42,846
ffi-buffer-clisp.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/ffi-buffer-clisp.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. ;;;; CLISP speedup comments by Pixel / pinterface, 2007, ;;;; copied from https://code.kepibu.org/cl+ssl/ ;;;; ;;;; ## Speeding Up clisp ;;;; cl+ssl has some serious speed issues on CLISP. For small requests, ;;;; it's not enough to worry about, but on larger requests the speed ;;;; issue can mean the difference between a 15 second download and a 15 ;;;; minute download. And that just won't do! ;;;; ;;;; ### What Makes cl+ssl on clisp so slow? ;;;; On clisp, cffi's with-pointer-to-vector-data macro uses copy-in, ;;;; copy-out semantics, because clisp doesn't offer a with-pinned-object ;;;; facility or some other way of getting at the pointer to a simple-array. ;;;; Very sad, I know. In addition to being a leaky abstraction, wptvd is really slow. ;;;; ;;;; ### How to Speed Things Up? ;;;; The simplest thing that can possibly work: break the abstraction. ;;;; I introduce several new functions (buffer-length, buffer-elt, etc.) ;;;; and use those wherever an ssl-stream-*-buffer happens to be used, ;;;; in place of the corresponding sequence functions. ;;;; Those buffer-* functions operate on clisp's ffi:pointer objects, ;;;; resulting in a tremendous speedup--and probably a memory leak or two. ;;;; ;;;; ### This Is Not For You If... ;;;; While I've made an effort to ensure this patch doesn't break other ;;;; implementations, if you have code which relies on ssl-stream-*-buffer ;;;; returning an array you can use standard CL functions on, it will break ;;;; on clisp under this patch. But you weren't relying on cl+ssl ;;;; internals anyway, now were you? #+xcvb (module (:depends-on ("package" "reload" "conditions" "ffi" "ffi-buffer-all"))) (in-package :cl+ssl) (defclass clisp-ffi-buffer () ((size :initarg :size :accessor clisp-ffi-buffer-size) (pointer :initarg :pointer :accessor clisp-ffi-buffer-pointer))) (defun make-buffer (size) (make-instance 'clisp-ffi-buffer :size size :pointer (cffi-sys:%foreign-alloc size))) (defun buffer-length (buf) (clisp-ffi-buffer-size buf)) (defun buffer-elt (buf index) (ffi:memory-as (clisp-ffi-buffer-pointer buf) 'ffi:uint8 index)) (defun set-buffer-elt (buf index val) (setf (ffi:memory-as (clisp-ffi-buffer-pointer buf) 'ffi:uint8 index) val)) (defsetf buffer-elt set-buffer-elt) (declaim (inline calc-buf-end)) ;; to calculate non NIL value of the buffer end index (defun calc-buf-end (buf-start seq seq-start seq-end) (+ buf-start (- (or seq-end (length seq)) seq-start))) (defun s/b-replace (seq buf &key (start1 0) end1 (start2 0) end2) (when (null end2) (setf end2 (calc-buf-end start2 seq start1 end1))) (replace seq (ffi:memory-as (clisp-ffi-buffer-pointer buf) (ffi:parse-c-type `(ffi:c-array ffi:uint8 ,(- end2 start2))) start2) :start1 start1 :end1 end1)) (defun as-vector (seq) (if (typep seq 'vector) seq (make-array (length seq) :initial-contents seq :element-type '(unsigned-byte 8)))) (defun b/s-replace (buf seq &key (start1 0) end1 (start2 0) end2) (when (null end1) (setf end1 (calc-buf-end start1 seq start2 end2))) (setf (ffi:memory-as (clisp-ffi-buffer-pointer buf) (ffi:parse-c-type `(ffi:c-array ffi:uint8 ,(- end1 start1))) start1) (as-vector (subseq seq start2 end2))) seq) (defmacro with-pointer-to-vector-data ((ptr buf) &body body) `(let ((,ptr (clisp-ffi-buffer-pointer ,buf))) ,@body))
3,708
Common Lisp
.lisp
87
39.091954
111
0.68265
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
999d5b2edace88480a03f704565532be41e77518072aab31c5c4ac2d86e43f45
42,846
[ -1 ]
42,847
package.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/package.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2001, 2003 Eric Marsden ;;; Copyright (C) 2005 David Lichteblau ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt." ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ((:when (:featurep :sbcl) (:require :sb-posix))))) (in-package :cl-user) (defpackage :cl+ssl (:export ;; Create TLS stream over TCP stream #:make-ssl-client-stream #:make-ssl-server-stream ;; Custom CTX creation #:make-context #:ssl-ctx-free ;; Custom binding for the global CTX #:with-global-context ;; Configure the global CTX #:use-certificate-chain-file #:ssl-load-global-verify-locations #:ssl-set-global-default-verify-paths ;; PEM file reading #:with-pem-password ;; Properties of an established TLS session #:get-selected-alpn-protocol ;; x509 Certificates ;; Obtain #:decode-certificate-from-file #:decode-certificate #:ssl-stream-x509-certificate ;; Release #:x509-free ;; Accessors #:certificate-not-after-time #:certificate-not-before-time #:certificate-subject-common-names #:certificate-fingerprint ;; (low level function, already ;; employed by make-ssl-client-stream ;; if verification is enabled and hostname ;; is passed in) #:verify-hostname ;; Saving / loading Lisp image #:reload ;; Various #:stream-fd #:random-bytes #:ensure-initialized ;; Default values #:*default-cipher-list* #:*default-buffer-size* #:*make-ssl-client-stream-verify-default* #:*default-unwrap-stream-p* ;; Error conditions. ;; Not full list, there are more non-exported, ;; including the base classes. ;; Should we export them all? #:ssl-error-verify #:ssl-error-stream #:ssl-error-code #:ssl-error-initialize ;; OpenSSL API constants #:+ssl-verify-none+ #:+ssl-verify-peer+ #:+ssl-verify-fail-if-no-peer-cert+ #:+ssl-verify-client-once+ #:+ssl-op-no-sslv2+ #:+ssl-op-no-sslv3+ #:+ssl-op-no-tlsv1+ #:+ssl-op-no-tlsv1-1+ #:+ssl-op-no-tlsv1-2+ #:+ssl-sess-cache-off+ #:+ssl-sess-cache-client+ #:+ssl-sess-cache-server+ #:+ssl-sess-cache-both+ #:+ssl-sess-cache-no-auto-clear+ #:+ssl-sess-cache-no-internal-lookup+ #:+ssl-sess-cache-no-internal-store+ #:+ssl-sess-cache-no-internal+ ;; DEPRECATED. ;; Use the (MAKE-SSL-CLIENT-STREAM .. :VERIFY ?) to enable/disable verification. ;; MAKE-CONTEXT also allows to enab/disable verification. #:ssl-check-verify-p ) (:use :common-lisp :trivial-gray-streams) (:import-from :cl+ssl/config #:libssl #:libcrypto))
2,810
Common Lisp
.lisp
91
26.791209
111
0.674565
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5c77582fb272082a4830a2d5ed99bd6a4b7e22e9801a1ac2ce6638ad71c7b2de
42,847
[ -1 ]
42,848
verify-hostname.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/verify-hostname.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl) (define-condition hostname-verification-error (error) ()) (define-condition unable-to-match-altnames (hostname-verification-error) ()) (define-condition unable-to-decode-common-name (hostname-verification-error) ()) (define-condition unable-to-match-common-name (hostname-verification-error) ()) (defun case-insensitive-match (name hostname) (string-equal name hostname)) (defun remove-trailing-dot (string) (string-right-trim '(#\.) string)) (defun check-wildcard-in-leftmost-label (identifier wildcard-pos) (alexandria:when-let ((dot-pos (position #\. identifier))) (> dot-pos wildcard-pos))) (defun check-single-wildcard (identifier wildcard-pos) (not (find #\* identifier :start (1+ wildcard-pos)))) (defun check-two-labels-after-wildcard (after-wildcard) ;;at least two dots(in fact labels since we remove trailing dot first) after wildcard (alexandria:when-let ((first-dot-aw-pos (position #\. after-wildcard))) (and (find #\. after-wildcard :start (1+ first-dot-aw-pos)) first-dot-aw-pos))) (defun validate-and-parse-wildcard-identifier (identifier hostname) (alexandria:when-let ((wildcard-pos (position #\* identifier))) (when (and (>= (length hostname) (length identifier)) ;; wildcard should constiute at least one character (check-wildcard-in-leftmost-label identifier wildcard-pos) (check-single-wildcard identifier wildcard-pos)) (let ((after-wildcard (subseq identifier (1+ wildcard-pos))) (before-wildcard (subseq identifier 0 wildcard-pos))) (alexandria:when-let ((first-dot-aw-pos (check-two-labels-after-wildcard after-wildcard))) (if (and (= 0 (length before-wildcard)) ;; nothing before wildcard (= wildcard-pos first-dot-aw-pos)) ;; i.e. dot follows * (values t before-wildcard after-wildcard t) (values t before-wildcard after-wildcard nil))))))) (defun wildcard-not-in-a-label (before-wildcard after-wildcard) (let ((after-w-dot-pos (position #\. after-wildcard))) (and (not (search "xn--" before-wildcard)) (not (search "xn--" (subseq after-wildcard 0 after-w-dot-pos)))))) (defun try-match-wildcard (before-wildcard after-wildcard single-char-wildcard pattern) ;; Compare AfterW part with end of pattern with length (length AfterW) ;; was Wildcard the only character in left-most label in identifier ;; doesn't matter since parts after Wildcard should match unconditionally. ;; However if Wildcard was the only character in left-most label we can't match this *.example.com and bar.foo.example.com ;; if i'm correct if it wasn't the only character ;; we can match like this: *o.example.com = bar.foo.example.com ;; but this is prohibited anyway thanks to check-vildcard-in-leftmost-label (if single-char-wildcard (let ((pattern-except-left-most-label (alexandria:if-let ((first-hostname-dot-post (position #\. pattern))) (subseq pattern first-hostname-dot-post) pattern))) (case-insensitive-match after-wildcard pattern-except-left-most-label)) (when (wildcard-not-in-a-label before-wildcard after-wildcard) ;; baz*.example.net and *baz.example.net and b*z.example.net would ;; be taken to match baz1.example.net and foobaz.example.net and ;; buzz.example.net, respectively (and (case-insensitive-match before-wildcard (subseq pattern 0 (length before-wildcard))) (case-insensitive-match after-wildcard (subseq pattern (- (length pattern) (length after-wildcard)))))))) (defun maybe-try-match-wildcard (name hostname) (multiple-value-bind (valid before-wildcard after-wildcard single-char-wildcard) (validate-and-parse-wildcard-identifier name hostname) (when valid (try-match-wildcard before-wildcard after-wildcard single-char-wildcard hostname)))) (defun try-match-hostname (name hostname) (let ((name (remove-trailing-dot name)) (hostname (remove-trailing-dot hostname))) (or (case-insensitive-match name hostname) (maybe-try-match-wildcard name hostname)))) (defun try-match-hostnames (names hostname) (loop for name in names when (try-match-hostname name hostname) do (return t))) (defun maybe-check-subject-cn (dns-names cert hostname) (or (some (lambda (dns) (try-match-hostname dns hostname)) dns-names) (alexandria:if-let ((cns (certificate-subject-common-names cert))) (or (some (lambda (cn) (try-match-hostname cn hostname)) cns) (error 'unable-to-match-common-name)) (error 'unable-to-decode-common-name)))) (defun verify-hostname (cert hostname) (let* ((dns-names (certificate-dns-alt-names cert))) (or (try-match-hostnames dns-names hostname) (maybe-check-subject-cn dns-names cert hostname))))
5,277
Common Lisp
.lisp
96
47.614583
124
0.680356
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
af4e18da86e2756f4dd6a9e26e3108db64707df1363ebf0f98ae9fe87cac50e8
42,848
[ -1 ]
42,849
ffi-buffer.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/ffi-buffer.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package"))) (in-package :cl+ssl) (defun make-buffer (size) (cffi:make-shareable-byte-vector size)) (defun buffer-length (buf) (length buf)) (defun buffer-elt (buf index) (elt buf index)) (defun set-buffer-elt (buf index val) (setf (elt buf index) val)) (defsetf buffer-elt set-buffer-elt) (defun s/b-replace (seq buf &key (start1 0) end1 (start2 0) end2) (replace seq buf :start1 start1 :end1 end1 :start2 start2 :end2 end2)) (defun b/s-replace (buf seq &key (start1 0) end1 (start2 0) end2) (replace buf seq :start1 start1 :end1 end1 :start2 start2 :end2 end2)) (defmacro with-pointer-to-vector-data ((ptr buf) &body body) `(cffi:with-pointer-to-vector-data (,ptr ,buf) ,@body))
971
Common Lisp
.lisp
23
38.826087
112
0.685225
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e945832a6edeff8ec59613d7b7ce63fcb14fc25ea00bf33c6eae4f09dc10b05f
42,849
[ -1 ]
42,850
config.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/config.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl-user) (defpackage :cl+ssl/config (:use :common-lisp) (:export #:define-libssl-path #:define-libcrypto-path)) (in-package :cl+ssl/config) (defvar *libssl-override* nil) (defvar *libcrypto-override* nil) (defmacro define-libssl-path (path) "Define the path where libssl resides to be PATH (not evaluated). This macroshould be used before loading CL+SSL. For instance, this defines libssl as \"/opt/local/lib/libssl.dylib\": (ql:quickload :cl+ssl/config) (cl+ssl:define-libssl-path \"/opt/local/lib/libssl.dylib\") (ql:quickload :cl+ssl)" `(progn (cffi:define-foreign-library libssl (t ,path)) (setq *libssl-override* t))) (defmacro define-libcrypto-path (path) "Define the path where libcrypto resides to be PATH (not evaluated). This macro should be used before loading CL+SSL." `(progn (cffi:define-foreign-library libcrypto (t ,path)) (setq *libcrypto-override* t)))
1,153
Common Lisp
.lisp
29
36.586207
111
0.71147
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5f202f5b6b6abeefacde6a7495b206c337bc6ff381ff05d33a850e0164aa486d
42,850
[ -1 ]
42,851
conditions.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/conditions.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2001, 2003 Eric Marsden ;;; Copyright (C) 2005 David Lichteblau ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt." ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package"))) (in-package :cl+ssl) (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +ssl-error-none+ 0) (defconstant +ssl-error-ssl+ 1) (defconstant +ssl-error-want-read+ 2) (defconstant +ssl-error-want-write+ 3) (defconstant +ssl-error-want-x509-lookup+ 4) (defconstant +ssl-error-syscall+ 5) (defconstant +ssl-error-zero-return+ 6) (defconstant +ssl-error-want-connect+ 7)) ;;; Condition hierarchy ;;; (defun read-ssl-error-queue () (loop :for error-code = (err-get-error) :until (zerop error-code) :collect error-code)) (defun format-ssl-error-queue (stream-designator queue-designator) "STREAM-DESIGNATOR is the same as CL:FORMAT accepts: T, NIL, or a stream. QUEUE-DESIGNATOR is either a list of error codes (as returned by READ-SSL-ERROR-QUEUE) or an SSL-ERROR condition." (flet ((body (stream) ;; If printed-queue is present, just use it (when (and (typep queue-designator 'ssl-error) (printed-queue queue-designator)) (format stream "ERR_print_errors(): ~A" (printed-queue queue-designator)) (return-from body)) (let ((queue (etypecase queue-designator (ssl-error (ssl-error-queue queue-designator)) (list queue-designator)))) (format stream "SSL error queue") (if queue (progn (format stream ":~%") (loop :for error-code :in queue :do (format stream "~a~%" (err-error-string error-code (cffi:null-pointer))))) (format stream " is empty."))))) (case stream-designator ((t) (body *standard-output*)) ((nil) (let ((s (make-string-output-stream :element-type 'character))) (unwind-protect (body s) (close s)) (get-output-stream-string s))) (otherwise (body stream-designator))))) (define-condition cl+ssl-error (error) ()) (define-condition ssl-error (cl+ssl-error) ( ;; Stores list of error codes ;; (as returned by the READ-SSL-ERROR-QUEUE function) (queue :initform nil :initarg :queue :reader ssl-error-queue) ;; The queue formatted using ERR_print_errors. ;; If this value is present, ignore the QUEUE field (which will ;; be empty, most likely, because ERR_print_errors cleans the queue). ;; ;; That's the preferred way, becuase it includes more info ;; the printing we implemented in Lisp. In particualr, in includes ;; the optional string added by ERR_add_error_data, which ;; we use to provide error details of unexpected lisp errors ;; in Lisp BIO. Consider migrating all the code to PRINTED-QUEUE, ;; for example, when working on ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/75. (printed-queue :initform nil :initarg :printed-queue :reader printed-queue))) (define-condition ssl-error/handle (ssl-error) ((ret :initarg :ret :reader ssl-error-ret) (handle :initarg :handle :reader ssl-error-handle)) (:report (lambda (condition stream) (format stream "Unspecified error ~A on handle ~A. " (ssl-error-ret condition) (ssl-error-handle condition)) (format-ssl-error-queue stream condition)))) (define-condition ssl-error-initialize (ssl-error) ((reason :initarg :reason :reader ssl-error-reason)) (:report (lambda (condition stream) (format stream "SSL initialization error: ~A. " (ssl-error-reason condition)) (format-ssl-error-queue stream condition)))) (define-condition ssl-error-want-something (ssl-error/handle) ()) ;;;SSL_ERROR_NONE (define-condition ssl-error-none (ssl-error/handle) () (:documentation "The TLS/SSL I/O operation completed. This result code is returned if and only if ret > 0.") (:report (lambda (condition stream) (format stream "The TLS/SSL operation on handle ~A completed (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_ZERO_RETURN (define-condition ssl-error-zero-return (ssl-error/handle) () (:documentation "The TLS/SSL connection has been closed. If the protocol version is SSL 3.0 or TLS 1.0, this result code is returned only if a closure alert has occurred in the protocol, i.e. if the connection has been closed cleanly. Note that in this case SSL_ERROR_ZERO_RETURN does not necessarily indicate that the underlying transport has been closed.") (:report (lambda (condition stream) (format stream "The TLS/SSL connection on handle ~A has been closed (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_WANT_READ (define-condition ssl-error-want-read (ssl-error-want-something) () (:documentation "The operation did not complete; the same TLS/SSL I/O function should be called again later. If, by then, the underlying BIO has data available for reading (if the result code is SSL_ERROR_WANT_READ) or allows writing data (SSL_ERROR_WANT_WRITE), then some TLS/SSL protocol progress will take place, i.e. at least part of an TLS/SSL record will be read or written. Note that the retry may again lead to a SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE condition. There is no fixed upper limit for the number of iterations that may be necessary until progress becomes visible at application protocol level.") (:report (lambda (condition stream) (format stream "The TLS/SSL operation on handle ~A did not complete: It wants a READ (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_WANT_WRITE (define-condition ssl-error-want-write (ssl-error-want-something) () (:documentation "The operation did not complete; the same TLS/SSL I/O function should be called again later. If, by then, the underlying BIO has data available for reading (if the result code is SSL_ERROR_WANT_READ) or allows writing data (SSL_ERROR_WANT_WRITE), then some TLS/SSL protocol progress will take place, i.e. at least part of an TLS/SSL record will be read or written. Note that the retry may again lead to a SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE condition. There is no fixed upper limit for the number of iterations that may be necessary until progress becomes visible at application protocol level.") (:report (lambda (condition stream) (format stream "The TLS/SSL operation on handle ~A did not complete: It wants a WRITE (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_WANT_CONNECT (define-condition ssl-error-want-connect (ssl-error-want-something) () (:documentation "The operation did not complete; the same TLS/SSL I/O function should be called again later. The underlying BIO was not connected yet to the peer and the call would block in connect()/accept(). The SSL function should be called again when the connection is established. These messages can only appear with a BIO_s_connect() or BIO_s_accept() BIO, respectively. In order to find out, when the connection has been successfully established, on many platforms select() or poll() for writing on the socket file descriptor can be used.") (:report (lambda (condition stream) (format stream "The TLS/SSL operation on handle ~A did not complete: It wants a connect first (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_WANT_X509_LOOKUP (define-condition ssl-error-want-x509-lookup (ssl-error-want-something) () (:documentation "The operation did not complete because an application callback set by SSL_CTX_set_client_cert_cb() has asked to be called again. The TLS/SSL I/O function should be called again later. Details depend on the application.") (:report (lambda (condition stream) (format stream "The TLS/SSL operation on handle ~A did not complete: An application callback wants to be called again (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_SYSCALL (define-condition ssl-error-syscall (ssl-error/handle) ((syscall :initarg :syscall)) (:documentation "Some I/O error occurred. The OpenSSL error queue may contain more information on the error. If the error queue is empty (i.e. ERR_get_error() returns 0), ret can be used to find out more about the error: If ret == 0, an EOF was observed that violates the protocol. If ret == -1, the underlying BIO reported an I/O error (for socket I/O on Unix systems, consult errno for details).") (:report (lambda (condition stream) (if (zerop (length (ssl-error-queue condition))) (case (ssl-error-ret condition) (0 (format stream "An I/O error occurred: An unexpected EOF was observed on handle ~A (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition))) (-1 (format stream "An I/O error occurred in the underlying BIO (return code: ~A). " (ssl-error-ret condition))) (otherwise (format stream "An I/O error occurred: undocumented reason (return code: ~A). " (ssl-error-ret condition)))) (format stream "An UNKNOWN I/O error occurred in the underlying BIO (return code: ~A). " (ssl-error-ret condition))) (format-ssl-error-queue stream condition)))) ;; SSL_ERROR_SSL (define-condition ssl-error-ssl (ssl-error/handle) () (:documentation "A failure in the SSL library occurred, usually a protocol error. The OpenSSL error queue contains more information on the error.") (:report (lambda (condition stream) (format stream "A failure in the SSL library occurred on handle ~A (return code: ~A). " (ssl-error-handle condition) (ssl-error-ret condition)) (format-ssl-error-queue stream condition)))) (defun ssl-signal-error (handle syscall error-code original-error) (let ((printed-queue (err-print-errors-to-string)) (queue (read-ssl-error-queue))) ;; BAD: The IF below is responsible to represent the "Unexpected EOF" ;; situation, which is when the remote peer closes ;; TCP connection without sending TLS close_notify alert, ;; as a situation of normal close_notify alert received. ;; ;; OpenSSL before version 3.0 signals the Unexpected EOF ;; as error-code = SSL_ERROR_SYSCALL and original-error = 0. ;; Normal termination is signalled by error-code = SSL_ERROR_ZERO_RETURN. ;; ;; As you see below, the IF turns the former into the latter. ;; ;; We should not suppress the Unexpected EOF error, because ;; some protocols on top of TLS may be attacked with TLS truncation ;; attack. For example HTTP 0.9, where response size is not specified ;; by the server but instead end of message is indicated by server closing ;; the connection. ;; ;; In such protocols a malicious middle-man can insert an unencrypted ;; TCP FIN packet, thus giving the client a partial response. OpenSSL treats ;; this as an Unexpected EOF error, but cl+ssl turns it into ;; the ssl-error-zero-return condition, which is then internally ;; converted simply to an end of ssl-stream. Thus the user will treat ;; the truncated response as authoritative and complete. ;; ;; Since OpenSSL 3.0 the suppression does not happen ;; and cl+ssl user receives an error condition, because ;; the Unexpected EOF is reported as error-code = SSL_ERROR_SSL. ;; ;; The only reason we currently keep this not fixed for older OpenSSL ;; is potential backwards compatibility problems with existing ;; Common Lisp libraries and applications and the fact ;; that protocols where message sizes are usually ;; explicitly indicated (like HTTP 1.1 where Content-Length or ;; chunked encoding are used) truncation can be detected ;; without relying to TLS and thus some servers close TCP ;; connections without sending TLS close_notify alert. ;; Some libraries or applications may be relying onto ;; silent end of stream after full message is received ;; according to the size indicated by the protocol. ;; ;; See one example of this, discussion and links in ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/166 (if (and (eql error-code #.+ssl-error-syscall+) (not (zerop original-error))) (error 'ssl-error-syscall :handle handle :ret error-code :printed-queue printed-queue :queue queue :syscall syscall) (error (case error-code (#.+ssl-error-none+ 'ssl-error-none) (#.+ssl-error-ssl+ 'ssl-error-ssl) (#.+ssl-error-want-read+ 'ssl-error-want-read) (#.+ssl-error-want-write+ 'ssl-error-want-write) (#.+ssl-error-want-x509-lookup+ 'ssl-error-want-x509-lookup) (#.+ssl-error-zero-return+ 'ssl-error-zero-return) (#.+ssl-error-want-connect+ 'ssl-error-want-connect) (#.+ssl-error-syscall+ 'ssl-error-zero-return) ; this is intentional here. we got an EOF from the syscall (ret is 0) (t 'ssl-error/handle)) :handle handle :ret error-code :printed-queue printed-queue :queue queue)))) (defparameter *ssl-verify-error-alist* '((0 :X509_V_OK) (2 :X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) (3 :X509_V_ERR_UNABLE_TO_GET_CRL) (4 :X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE) (5 :X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE) (6 :X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY) (7 :X509_V_ERR_CERT_SIGNATURE_FAILURE) (8 :X509_V_ERR_CRL_SIGNATURE_FAILURE) (9 :X509_V_ERR_CERT_NOT_YET_VALID) (10 :X509_V_ERR_CERT_HAS_EXPIRED) (11 :X509_V_ERR_CRL_NOT_YET_VALID) (12 :X509_V_ERR_CRL_HAS_EXPIRED) (13 :X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD) (14 :X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD) (15 :X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD) (16 :X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD) (17 :X509_V_ERR_OUT_OF_MEM) (18 :X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) (19 :X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) (20 :X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) (21 :X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE) (22 :X509_V_ERR_CERT_CHAIN_TOO_LONG) (23 :X509_V_ERR_CERT_REVOKED) (24 :X509_V_ERR_INVALID_CA) (25 :X509_V_ERR_PATH_LENGTH_EXCEEDED) (26 :X509_V_ERR_INVALID_PURPOSE) (27 :X509_V_ERR_CERT_UNTRUSTED) (28 :X509_V_ERR_CERT_REJECTED) (29 :X509_V_ERR_SUBJECT_ISSUER_MISMATCH) (30 :X509_V_ERR_AKID_SKID_MISMATCH) (31 :X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH) (32 :X509_V_ERR_KEYUSAGE_NO_CERTSIGN) (50 :X509_V_ERR_APPLICATION_VERIFICATION))) (defun ssl-verify-error-keyword (code) (cadr (assoc code *ssl-verify-error-alist*))) (defun ssl-verify-error-code (keyword) (caar (member keyword *ssl-verify-error-alist* :key #'cadr))) (define-condition ssl-error-verify (ssl-error) ((stream :initarg :stream :reader ssl-error-stream :documentation "The SSL stream whose peer certificate didn't verify.") (error-code :initarg :error-code :reader ssl-error-code :documentation "The peer certificate verification error code.")) (:report (lambda (condition stream) (let ((code (ssl-error-code condition))) (format stream "SSL verify error: ~d~@[ ~a~]" code (ssl-verify-error-keyword code))))) (:documentation "This condition is signalled on SSL connection when a peer certificate doesn't verify.")) (define-condition ssl-error-call (ssl-error) ((message :initarg :message)) (:documentation "A failure in the SSL library occurred..") (:report (lambda (condition stream) (format stream "A failure in OpenSSL library occurred~@[: ~A~]. " (slot-value condition 'message)) (format-ssl-error-queue stream (ssl-error-queue condition))))) (define-condition asn1-error (cl+ssl-error) () (:documentation "Asn1 syntax error")) (define-condition invalid-asn1-string (cl+ssl-error) ((type :initarg :type :initform nil)) (:documentation "ASN.1 string parsing/validation error") (:report (lambda (condition stream) (format stream "ASN.1 syntax error: invalid asn1 string (expected type ~a)" (slot-value condition 'type))))) ;; TODO: when moved to grovel use enum symbol here (define-condition server-certificate-missing (cl+ssl-error simple-error) () (:documentation "SSL server didn't present a certificate"))
18,208
Common Lisp
.lisp
359
42.70195
172
0.658621
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
b8c877c940f20ec28af3803f7a576b228dcc1c06fa9903f3923356232a3c821e
42,851
[ -1 ]
42,852
ffi.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/ffi.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2001, 2003 Eric Marsden ;;; Copyright (C) 2005 David Lichteblau ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt." ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package" "conditions"))) (eval-when (:compile-toplevel) (declaim (optimize (speed 3) (space 1) (safety 1) (debug 0) (compilation-speed 0)))) (in-package :cl+ssl) ;;; Some lisps (CMUCL) fail when we try to define ;;; a foreign function which is absent in the loaded ;;; foreign library. CMUCL fails when the compiled .fasl ;;; file is loaded, and the failure can not be ;;; captured even by CL condition handlers, i.e. ;;; wrapping (defcfun "removed-function" ...) ;;; into (ignore-errors ...) doesn't help. ;;; ;;; See https://gitlab.common-lisp.net/cmucl/cmucl/issues/74 ;;; ;;; As OpenSSL often changs API (removes / adds functions) ;;; we need to solve this problem for CMUCL. ;;; ;;; We do this on CMUCL by calling functions which exists ;;; not in all OpenSSL versions through a pointer ;;; received with cffi:foreign-symbol-pointer. ;;; So a lisp wrapper function for such foreign function ;;; looks up a pointer to the required foreign function ;;; in a hash table. (defparameter *late-bound-foreign-function-pointers* (make-hash-table :test 'equal)) (defmacro defcfun-late-bound (name-and-options &body body) (assert (not (eq (alexandria:lastcar body) '&rest)) (body) "The BODY format is implemented in a limited way comparing to CFFI:DEFCFUN - we don't support the &REST which specifies vararg functions. Feel free to implement the support if you have a use case.") (assert (and (>= (length name-and-options) 2) (stringp (first name-and-options)) (symbolp (second name-and-options))) (name-and-options) "Unsupported NAME-AND-OPTIONS format: ~S. \(Of all the NAME-AND-OPTIONS variants allowed by CFFI:DEFCFUN we have only implemented support for (FOREIGN-NAME LISP-NAME ...) where FOREIGN-NAME is a STRING and LISP-NAME is a SYMBOL. Fell free to implement support the remaining variants if you have use cases for them.)" name-and-options) (let ((foreign-name-str (first name-and-options)) (lisp-name (second name-and-options)) (docstring (when (stringp (car body)) (pop body))) (return-type (first body)) (arg-names (mapcar #'first (rest body))) (arg-types (mapcar #'second (rest body))) (library (getf (cddr name-and-options) :library)) (convention (getf (cddr name-and-options) :convention)) (ptr-var (gensym (string 'ptr)))) `(progn (setf (gethash ,foreign-name-str *late-bound-foreign-function-pointers*) (or (cffi:foreign-symbol-pointer ,foreign-name-str ,@(when library `(:library ',library))) 'foreign-symbol-not-found)) (defun ,lisp-name (,@arg-names) ,@(when docstring (list docstring)) (let ((,ptr-var (gethash ,foreign-name-str *late-bound-foreign-function-pointers*))) (when (null ,ptr-var) (error "Unexpacted state, no value in *late-bound-foreign-function-pointers* for ~A" ,foreign-name-str)) (when (eq ,ptr-var 'foreign-symbol-not-found) (error "The current version of OpenSSL libcrypto doesn't provide ~A" ,foreign-name-str)) (cffi:foreign-funcall-pointer ,ptr-var ,(when convention (list convention)) ,@(mapcan #'list arg-types arg-names) ,return-type)))))) (defmacro defcfun-versioned ((&key since vanished) name-and-options &body body) (if (and (or since vanished) (member :cmucl *features*)) `(defcfun-late-bound ,name-and-options ,@body) `(cffi:defcfun ,name-and-options ,@body))) ;;; Code for checking that we got the correct foreign symbols right. ;;; Implemented only for LispWorks for now. (defvar *cl+ssl-ssl-foreign-function-names* nil) (defvar *cl+ssl-crypto-foreign-function-names* nil) #+lispworks (defun check-cl+ssl-symbols () (dolist (ssl-symbol *cl+ssl-ssl-foreign-function-names*) (when (fli:null-pointer-p (fli:make-pointer :symbol-name ssl-symbol :module 'libssl :errorp nil)) (format *error-output* "cl+ssl can not locate symbol ~s in the module 'libssl~%" ssl-symbol))) (dolist (crypto-symbol *cl+ssl-crypto-foreign-function-names*) (when (fli:null-pointer-p (fli:make-pointer :symbol-name crypto-symbol :module 'libcrypto :errorp nil)) (format *error-output* "cl+ssl can not locate symbol ~s in the module 'libcrypto~%" crypto-symbol)))) (defmacro define-ssl-function-ex ((&key since vanished) name-and-options &body body) `(progn ;; debugging ,@(unless (or since vanished) `((pushnew ,(car name-and-options) *cl+ssl-ssl-foreign-function-names* :test 'equal))) (defcfun-versioned (:since ,since :vanished ,vanished) ,(append name-and-options '(:library libssl)) ,@body))) (defmacro define-ssl-function (name-and-options &body body) `(define-ssl-function-ex () ,name-and-options ,@body)) (defmacro define-crypto-function-ex ((&key since vanished) name-and-options &body body) `(progn ;; debugging ,@(unless (or since vanished) `(( pushnew ,(car name-and-options) *cl+ssl-crypto-foreign-function-names* :test 'equal))) (defcfun-versioned (:since ,since :vanished ,vanished) ,(append name-and-options #-cl+ssl-foreign-libs-already-loaded '(:library libcrypto)) ,@body))) (defmacro define-crypto-function (name-and-options &body body) `(define-crypto-function-ex () ,name-and-options ,@body)) ;;; Global state ;;; (defvar *ssl-global-context* nil) (defvar *ssl-global-method* nil) (defvar *bio-is-opaque* "Since openssl 1.1.0, bio properties should be accessed using functions, not directly using C structure slots. Intialized to T for such openssl versions.") (defvar *lisp-bio-type*) (defvar *bio-lisp-method* nil) (defparameter *blockp* t) (defun ssl-initialized-p () (and *ssl-global-context* *ssl-global-method*)) ;;; Constants ;;; (defconstant +ssl-filetype-pem+ 1) (defconstant +ssl-filetype-asn1+ 2) (defconstant +ssl-filetype-default+ 3) (defconstant +SSL-CTRL-OPTIONS+ 32) (defconstant +SSL_CTRL_SET_SESS_CACHE_MODE+ 44) (defconstant +SSL_CTRL_MODE+ 33) (defconstant +SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER+ 2) (defconstant +RSA_F4+ #x10001) (defconstant +SSL-SESS-CACHE-OFF+ #x0000 "No session caching for client or server takes place.") (defconstant +SSL-SESS-CACHE-CLIENT+ #x0001 "Client sessions are added to the session cache. As there is no reliable way for the OpenSSL library to know whether a session should be reused or which session to choose (due to the abstract BIO layer the SSL engine does not have details about the connection), the application must select the session to be reused by using the SSL-SET-SESSION function. This option is not activated by default.") (defconstant +SSL-SESS-CACHE-SERVER+ #x0002 "Server sessions are added to the session cache. When a client proposes a session to be reused, the server looks for the corresponding session in (first) the internal session cache (unless +SSL-SESS-CACHE-NO-INTERNAL-LOOKUP+ is set), then (second) in the external cache if available. If the session is found, the server will try to reuse the session. This is the default.") (defconstant +SSL-SESS-CACHE-BOTH+ (logior +SSL-SESS-CACHE-CLIENT+ +SSL-SESS-CACHE-SERVER+) "Enable both +SSL-SESS-CACHE-CLIENT+ and +SSL-SESS-CACHE-SERVER+ at the same time.") (defconstant +SSL-SESS-CACHE-NO-AUTO-CLEAR+ #x0080 "Normally the session cache is checked for expired sessions every 255 connections using the SSL-CTX-FLUSH-SESSIONS function. Since this may lead to a delay which cannot be controlled, the automatic flushing may be disabled and SSL-CTX-FLUSH-SESSIONS can be called explicitly by the application.") (defconstant +SSL-SESS-CACHE-NO-INTERNAL-LOOKUP+ #x0100 "By setting this flag, session-resume operations in an SSL/TLS server will not automatically look up sessions in the internal cache, even if sessions are automatically stored there. If external session caching callbacks are in use, this flag guarantees that all lookups are directed to the external cache. As automatic lookup only applies for SSL/TLS servers, the flag has no effect on clients.") (defconstant +SSL-SESS-CACHE-NO-INTERNAL-STORE+ #x0200 "Depending on the presence of +SSL-SESS-CACHE-CLIENT+ and/or +SSL-SESS-CACHE-SERVER+, sessions negotiated in an SSL/TLS handshake may be cached for possible reuse. Normally a new session is added to the internal cache as well as any external session caching (callback) that is configured for the SSL-CTX. This flag will prevent sessions being stored in the internal cache (though the application can add them manually using SSL-CTX-ADD-SESSION). Note: in any SSL/TLS servers where external caching is configured, any successful session lookups in the external cache (ie. for session-resume requests) would normally be copied into the local cache before processing continues - this flag prevents these additions to the internal cache as well.") (defconstant +SSL-SESS-CACHE-NO-INTERNAL+ (logior +SSL-SESS-CACHE-NO-INTERNAL-LOOKUP+ +SSL-SESS-CACHE-NO-INTERNAL-STORE+) "Enable both +SSL-SESS-CACHE-NO-INTERNAL-LOOKUP+ and +SSL-SESS-CACHE-NO-INTERNAL-STORE+ at the same time.") (defconstant +SSL-VERIFY-NONE+ #x00) (defconstant +SSL-VERIFY-PEER+ #x01) (defconstant +SSL-VERIFY-FAIL-IF-NO-PEER-CERT+ #x02) (defconstant +SSL-VERIFY-CLIENT-ONCE+ #x04) (defconstant +SSL-OP-ALL+ #x80000BFF) (defconstant +SSL-OP-IGNORE-UNEXPECTED-EOF+ #b10000000) (defconstant +SSL-OP-NO-SSLv2+ #x01000000) (defconstant +SSL-OP-NO-SSLv3+ #x02000000) (defconstant +SSL-OP-NO-TLSv1+ #x04000000) (defconstant +SSL-OP-NO-TLSv1-2+ #x08000000) (defconstant +SSL-OP-NO-TLSv1-1+ #x10000000) (defconstant +SSL-CTRL-SET-MIN-PROTO-VERSION+ 123) (defconstant +SSL-CTRL-SET-MAX-PROTO-VERSION+ 124) (defconstant +SSL3-VERSION+ #x0300) (defconstant +TLS1-VERSION+ #x0301) (defconstant +TLS1-1-VERSION+ #x0302) (defconstant +TLS1-2-VERSION+ #x0303) (defconstant +TLS1-3-VERSION+ #x0304) (defconstant +DTLS1-VERSION+ #xFEFF) (defconstant +DTLS1-2-VERSION+ #xFEFD) (defvar *tmp-rsa-key-512* nil) (defvar *tmp-rsa-key-1024* nil) (defvar *tmp-rsa-key-2048* nil) ;;; Misc ;;; (defmacro while (cond &body body) `(do () ((not ,cond)) ,@body)) ;;; Function definitions ;;; (cffi:defcfun (#-windows "close" #+windows "closesocket" close-socket) :int (socket :int)) (declaim (inline ssl-write ssl-read ssl-connect ssl-accept)) (cffi:defctype ssl-method :pointer) (cffi:defctype ssl-ctx :pointer) (cffi:defctype ssl-pointer :pointer) (define-crypto-function-ex (:vanished "1.1.0") ("SSLeay" ssl-eay) :long) (define-crypto-function-ex (:since "1.1.0") ("OpenSSL_version_num" openssl-version-num) :long) (defun compat-openssl-version () (or (ignore-errors (openssl-version-num)) (ignore-errors (ssl-eay)) (error "No OpenSSL version number could be determined, both SSLeay and OpenSSL_version_num failed."))) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter +openssl-version-status-strings+ '("dev" "beta 1" "beta 2" "beta 3" "beta 4" "beta 5" "beta 6" "beta 7" "beta 8" "beta 9" "beta 10" "beta 11" "beta 12" "beta 13" "beta 14" "release"))) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter +openssl-version-patch-characters+ '(#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z))) (deftype openssl-version-patch () `(or (integer 0 #xff) (member ,@+openssl-version-patch-characters+))) (eval-when (:compile-toplevel :load-toplevel :execute) (defun openssl-version-status-p (status) (or (typep status '(integer 0 #xf)) (member status +openssl-version-status-strings+ :test #'string=)))) (deftype openssl-version-status () '(satisfies openssl-version-status-p)) (defun encode-openssl-version-impl (major minor &optional (fix 0) (patch 0) (status "release")) (check-type major (integer 0 3)) (check-type minor (integer 0 #xff)) (check-type fix (integer 0 #xff)) (check-type patch openssl-version-patch) (check-type status openssl-version-status) (let ((patch-int (if (integerp patch) patch ;; a = 1, b = 2, and so on: (1+ (position patch +openssl-version-patch-characters+)))) (status-int (if (integerp status) status ;; dev = 0, beta 1 = 1, beta 2 = 2, ..., beta 14 = 14, release = 15 (position status +openssl-version-status-strings+ :test #'string=)))) (logior (ash major 28) (ash minor 20) (ash fix 12) (ash patch-int 4) status-int))) (assert (= (encode-openssl-version-impl 0 9 6 0 "dev") #x00906000)) (assert (= (encode-openssl-version-impl 0 9 6 #\b "beta 3") #x00906023)) (assert (= (encode-openssl-version-impl 0 9 6 #\e "release") #x0090605f)) (assert (= (encode-openssl-version-impl 0 9 6 #\e) #x0090605f)) (assert (= (encode-openssl-version-impl 1 0 0 #\s) #x1000013f)) (defun encode-openssl-version (major minor &optional (patch-or-fix 0)) "Builds a version number to compare with the version returned by OpenSSL. The integer representation of OpenSSL version has bit fields for major, minor, fix, patch and status varlues. Versions before OpenSSL 3 have user readable representations for all those fields. For example, 0.9.6b beta 3. Here 0 - major, 9 - minor, 6 - fix, b - patch, beta 3 - status. https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_VERSION_NUMBER.html Since OpenSSL 3, the third number in user readable repersentation is patch. The fix and status are not used and have 0 in the corresponding bit fields. https://www.openssl.org/docs/man3.0/man3/OPENSSL_VERSION_NUMBER.html https://www.openssl.org/policies/general/versioning-policy.html As usually with OpenSSL docs, if the above links disappear becuase those OpenSSL versions are out of maintenance, use the Wayback Machine. Note: the _really_ old formats (<= 0.9.4) are not supported." (if (>= major 3) (encode-openssl-version-impl major minor 0 patch-or-fix) (encode-openssl-version-impl major minor patch-or-fix))) (defun openssl-is-at-least (major minor &optional (patch-or-fix 0)) (>= (compat-openssl-version) (encode-openssl-version major minor patch-or-fix))) (defun openssl-is-not-even (major minor &optional (patch-or-fix 0)) (< (compat-openssl-version) (encode-openssl-version major minor patch-or-fix))) (defun libresslp () ;; LibreSSL can be distinguished by ;; OpenSSL_version_num() always returning 0x020000000, ;; where 2 is the major version number. ;; http://man.openbsd.org/OPENSSL_VERSION_NUMBER.3 ;; And OpenSSL will never use the major version 2: ;; "This document outlines the design of OpenSSL 3.0, the next version of OpenSSL after 1.1.1" ;; https://www.openssl.org/docs/OpenSSL300Design.html (= #x20000000 (compat-openssl-version))) (define-ssl-function ("SSL_get_version" ssl-get-version) :string (ssl ssl-pointer)) (define-ssl-function-ex (:vanished "1.1.0") ("SSL_load_error_strings" ssl-load-error-strings) :void) (define-ssl-function-ex (:vanished "1.1.0") ("SSL_library_init" ssl-library-init) :int) (define-ssl-function-ex (:vanished "1.1.0") ("OpenSSL_add_all_digests" openssl-add-all-digests) :void) ;; ;; We don't refer SSLv2_client_method as the default ;; builds of OpenSSL do not have it, due to insecurity ;; of the SSL v2 protocol (see https://www.openssl.org/docs/ssl/SSL_CTX_new.html ;; and https://github.com/cl-plus-ssl/cl-plus-ssl/issues/6) ;; ;; (define-ssl-function ("SSLv2_client_method" ssl-v2-client-method) ;; ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv23_client_method" ssl-v23-client-method) ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv23_server_method" ssl-v23-server-method) ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv23_method" ssl-v23-method) ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv3_client_method" ssl-v3-client-method) ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv3_server_method" ssl-v3-server-method) ssl-method) (define-ssl-function-ex (:vanished "1.1.0") ("SSLv3_method" ssl-v3-method) ssl-method) (define-ssl-function ("TLSv1_client_method" ssl-TLSv1-client-method) ssl-method) (define-ssl-function ("TLSv1_server_method" ssl-TLSv1-server-method) ssl-method) (define-ssl-function ("TLSv1_method" ssl-TLSv1-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_1_client_method" ssl-TLSv1-1-client-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_1_server_method" ssl-TLSv1-1-server-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_1_method" ssl-TLSv1-1-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_2_client_method" ssl-TLSv1-2-client-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_2_server_method" ssl-TLSv1-2-server-method) ssl-method) (define-ssl-function-ex (:since "1.0.2") ("TLSv1_2_method" ssl-TLSv1-2-method) ssl-method) (define-ssl-function-ex (:since "1.1.0") ("TLS_method" tls-method) ssl-method) (define-ssl-function ("SSL_CTX_new" ssl-ctx-new) ssl-ctx (method ssl-method)) (define-ssl-function ("SSL_new" ssl-new) ssl-pointer (ctx ssl-ctx)) (define-ssl-function ("SSL_get_fd" ssl-get-fd) :int (ssl ssl-pointer)) (define-ssl-function ("SSL_set_fd" ssl-set-fd) :int (ssl ssl-pointer) (fd :int)) (define-ssl-function ("SSL_set_bio" ssl-set-bio) :void (ssl ssl-pointer) (rbio :pointer) (wbio :pointer)) (define-ssl-function ("SSL_get_error" ssl-get-error) :int (ssl ssl-pointer) (ret :int)) (define-ssl-function ("SSL_set_connect_state" ssl-set-connect-state) :void (ssl ssl-pointer)) (define-ssl-function ("SSL_set_accept_state" ssl-set-accept-state) :void (ssl ssl-pointer)) (define-ssl-function ("SSL_connect" ssl-connect) :int (ssl ssl-pointer)) (define-ssl-function ("SSL_accept" ssl-accept) :int (ssl ssl-pointer)) (define-ssl-function ("SSL_write" ssl-write) :int (ssl ssl-pointer) (buf :pointer) (num :int)) (define-ssl-function ("SSL_read" ssl-read) :int (ssl ssl-pointer) (buf :pointer) (num :int)) (define-ssl-function ("SSL_shutdown" ssl-shutdown) :int (ssl ssl-pointer)) (define-ssl-function ("SSL_free" ssl-free) :void (ssl ssl-pointer)) (define-ssl-function ("SSL_CTX_free" ssl-ctx-free) :void (ctx ssl-ctx)) (define-ssl-function-ex (:since "1.0") ("SSL_set_alpn_protos" ssl-set-alpn-protos) :int (SSL :pointer) (text :string) (len :int)) (define-ssl-function-ex (:since "1.0") ("SSL_get0_alpn_selected" ssl-get0-alpn-selected) :void (SSL :pointer) (text (:pointer :string)) (len (:pointer :int))) (define-crypto-function ("BIO_ctrl" bio-set-fd) :long (bio :pointer) (cmd :int) (larg :long) (parg :pointer)) (define-crypto-function ("BIO_new_socket" bio-new-socket) :pointer (fd :int) (close-flag :int)) (define-crypto-function ("BIO_new" bio-new) :pointer (method :pointer)) (define-crypto-function ("BIO_free" bio-free) :pointer (method :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_get_new_index" bio-new-index) :int) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_new" bio-meth-new) :pointer (type :int) (name :string)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_puts" bio-set-puts) :int (meth :pointer) (puts :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_write" bio-set-write) :int (meth :pointer) (puts :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_read" bio-set-read) :int (meth :pointer) (read :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_gets" bio-set-gets) :int (meth :pointer) (read :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_create" bio-set-create) :int (meth :pointer) (read :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_destroy" bio-set-destroy) :int (meth :pointer) (read :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_meth_set_ctrl" bio-set-ctrl) :int (meth :pointer) (read :pointer)) (define-crypto-function-ex (:since "1.1.0") ("BIO_set_init" bio-set-init) :int (meth :pointer) (value :int)) (define-crypto-function-ex (:since "1.1.0") ("BIO_set_flags" bio-set-flags) :int (meth :pointer) (value :int)) (define-crypto-function-ex (:since "1.1.0") ("BIO_clear_flags" bio-clear-flags) :int (meth :pointer) (value :int)) (define-crypto-function-ex (:since "1.1.0") ("BIO_test_flags" bio-test-flags) :int (meth :pointer) (value :int)) (define-crypto-function ("ERR_get_error" err-get-error) :unsigned-long) (define-crypto-function ("ERR_error_string" err-error-string) :string (e :unsigned-long) (buf :pointer)) (define-crypto-function-ex (:vanished "3.0.0") ("ERR_put_error" err-put-error) :void (lib :int) (func :int) (reason :int) ;; The file is :pointer instead of :string, becasue the file ;; name should not be dalocated after the function call ;; returns - that must be a long living char array. (file :pointer) (line :int)) (defconstant +err_lib_none+ 1) (defconstant +err_r_fatal+ 64) (defconstant +err_r_internal_error+ (logior 4 +err_r_fatal+)) (define-crypto-function-ex (:since "3.0.0") ("ERR_new" err-new) :void) (define-crypto-function-ex (:since "3.0.0") ("ERR_set_debug" err-set-debug) :void (file :string) (line :int) (func :string)) #-cffi-sys::no-foreign-funcall ; vararg functions require foreign-funcall (define-crypto-function-ex (:since "3.0.0") ("ERR_set_error" err-set-error) :void (lib :int) (reason :int) (fmt :string) &rest) ;; Is that a new function in 1.0.2 or existed forever? (define-crypto-function-ex (:since "1.0.2") ("ERR_get_next_error_library" err-get-next-error-library) :int) #-cffi-sys::no-foreign-funcall ; vararg functions require foreign-funcall (define-crypto-function ("ERR_add_error_data" err-add-error-data) :void (num :int) &rest) ;; Is that a new function in 3.0.0 or existed before? (define-crypto-function-ex (:since "3.0.0") ("ERR_add_error_txt" err-add-error-txt) :void (sep :string) (txt :string)) (define-crypto-function ("ERR_print_errors" err-print-errors) :void (bio :pointer)) (define-ssl-function ("SSL_set_cipher_list" ssl-set-cipher-list) :int (ssl ssl-pointer) (str :string)) (define-ssl-function ("SSL_use_RSAPrivateKey_file" ssl-use-rsa-privatekey-file) :int (ssl ssl-pointer) (str :string) ;; either +ssl-filetype-pem+ or +ssl-filetype-asn1+ (type :int)) (define-ssl-function ("SSL_CTX_use_RSAPrivateKey_file" ssl-ctx-use-rsa-privatekey-file) :int (ctx ssl-ctx) (type :int)) (define-ssl-function ("SSL_use_PrivateKey_file" ssl-use-privatekey-file) :int (ssl ssl-pointer) (str :string) ;; either +ssl-filetype-pem+ or +ssl-filetype-asn1+ (type :int)) (define-ssl-function ("SSL_CTX_use_PrivateKey_file" ssl-ctx-use-privatekey-file) :int (ctx ssl-ctx) (file :string) (type :int)) (define-ssl-function ("SSL_use_certificate_file" ssl-use-certificate-file) :int (ssl ssl-pointer) (str :string) (type :int)) (define-ssl-function ("SSL_CTX_ctrl" ssl-ctx-ctrl) :long (ctx ssl-ctx) (cmd :int) ;; Despite declared as long in the original OpenSSL headers, ;; passing to larg for example 2181041151 which is the result of ;; (logior cl+ssl::+SSL-OP-ALL+ ;; cl+ssl::+SSL-OP-NO-SSLv2+ ;; cl+ssl::+SSL-OP-NO-SSLv3+) ;; causes CFFI on 32 bit platforms to signal an error ;; "The value 2181041151 is not of the expected type (SIGNED-BYTE 32)" ;; The problem is that 2181041151 requires 32 bits by itself and ;; there is no place left for the sign bit. ;; In C the compiler silently coerces unsigned to signed, ;; but CFFI raises this error. ;; Therefore we use :UNSIGNED-LONG for LARG. (larg :unsigned-long) (parg :pointer)) (define-ssl-function ("SSL_ctrl" ssl-ctrl) :long (ssl :pointer) (cmd :int) (larg :long) (parg :pointer)) #+new-openssl (define-ssl-function ("SSL_CTX_set_options" ssl-ctx-set-options) :long (ctx :pointer) (options :long)) #-new-openssl (defun ssl-ctx-set-options (ctx options) (ssl-ctx-ctrl ctx +SSL-CTRL-OPTIONS+ options (cffi:null-pointer))) (defun ssl-ctx-set-min-proto-version (ctx version) (ssl-ctx-ctrl ctx +SSL-CTRL-SET-MIN-PROTO-VERSION+ version (cffi:null-pointer))) (defun ssl-ctx-set-max-proto-version (ctx version) (ssl-ctx-ctrl ctx +SSL-CTRL-SET-MAX-PROTO-VERSION+ version (cffi:null-pointer))) (define-ssl-function ("SSL_CTX_set_cipher_list" ssl-ctx-set-cipher-list%) :int (ctx :pointer) (ciphers :pointer)) (defun ssl-ctx-set-cipher-list (ctx ciphers) (cffi:with-foreign-string (ciphers* ciphers) (when (= 0 (ssl-ctx-set-cipher-list% ctx ciphers*)) (error 'ssl-error-initialize :reason "Can't set SSL cipher list" :queue (read-ssl-error-queue))))) (define-ssl-function ("SSL_CTX_use_certificate_chain_file" ssl-ctx-use-certificate-chain-file) :int (ctx ssl-ctx) (str :string)) (define-ssl-function ("SSL_CTX_load_verify_locations" ssl-ctx-load-verify-locations) :int (ctx ssl-ctx) (CAfile :string) (CApath :string)) (define-ssl-function ("SSL_CTX_set_client_CA_list" ssl-ctx-set-client-ca-list) :void (ctx ssl-ctx) (list ssl-pointer)) (define-ssl-function ("SSL_load_client_CA_file" ssl-load-client-ca-file) ssl-pointer (file :string)) (define-ssl-function ("SSL_CTX_set_default_passwd_cb" ssl-ctx-set-default-passwd-cb) :void (ctx ssl-ctx) (pem_passwd_cb :pointer)) (define-crypto-function-ex (:vanished "1.1.0") ("CRYPTO_num_locks" crypto-num-locks) :int) (define-crypto-function-ex (:vanished "1.1.0") ("CRYPTO_set_locking_callback" crypto-set-locking-callback) :void (fun :pointer)) (define-crypto-function-ex (:vanished "1.1.0") ("CRYPTO_set_id_callback" crypto-set-id-callback) :void (fun :pointer)) (define-crypto-function ("RAND_seed" rand-seed) :void (buf :pointer) (num :int)) (define-crypto-function ("RAND_bytes" rand-bytes) :int (buf :pointer) (num :int)) (define-ssl-function ("SSL_CTX_set_verify_depth" ssl-ctx-set-verify-depth) :void (ctx :pointer) (depth :int)) (define-ssl-function ("SSL_CTX_set_verify" ssl-ctx-set-verify) :void (ctx :pointer) (mode :int) (verify-callback :pointer)) (define-ssl-function ("SSL_get_verify_result" ssl-get-verify-result) :long (ssl ssl-pointer)) (define-ssl-function-ex (:vanished "3.0.0") ("SSL_get_peer_certificate" ssl-get-peer-certificate) :pointer (ssl ssl-pointer)) (define-ssl-function-ex (:since "3.0.0") ("SSL_get1_peer_certificate" ssl-get1-peer-certificate) :pointer (ssl ssl-pointer)) (defun compat-ssl-get1-peer-certificate (handle) (funcall (if (openssl-is-at-least 3 0 0) 'ssl-get1-peer-certificate 'ssl-get-peer-certificate) handle)) ;;; X509 & ASN1 (define-crypto-function ("X509_free" x509-free) :void (x509 :pointer)) (define-crypto-function ("X509_NAME_oneline" x509-name-oneline) :pointer (x509-name :pointer) (buf :pointer) (size :int)) (define-crypto-function ("X509_NAME_get_index_by_NID" x509-name-get-index-by-nid) :int (name :pointer) (nid :int) (lastpos :int)) (define-crypto-function ("X509_NAME_get_entry" x509-name-get-entry) :pointer (name :pointer) (log :int)) (define-crypto-function ("X509_NAME_ENTRY_get_data" x509-name-entry-get-data) :pointer (name-entry :pointer)) (define-crypto-function ("X509_get_issuer_name" x509-get-issuer-name) :pointer ; *X509_NAME (x509 :pointer)) (define-crypto-function ("X509_get_subject_name" x509-get-subject-name) :pointer ; *X509_NAME (x509 :pointer)) (define-crypto-function-ex (:since "1.1.0") ("X509_get0_notBefore" x509-get0-not-before) :pointer ; *ASN1_TIME (x509 :pointer)) (define-crypto-function-ex (:since "1.1.0") ("X509_get0_notAfter" x509-get0-not-after) :pointer ; *ASN1_TIME (x509 :pointer)) (define-crypto-function ("X509_get_ext_d2i" x509-get-ext-d2i) :pointer (cert :pointer) (nid :int) (crit :pointer) (idx :pointer)) (define-crypto-function ("X509_STORE_CTX_get_error" x509-store-ctx-get-error) :int (ctx :pointer)) (define-crypto-function ("d2i_X509" d2i-x509) :pointer (*px :pointer) (in :pointer) (len :int)) (define-crypto-function ("X509_digest" x509-digest) :int (cert :pointer) (type :pointer) (buf :pointer) (*len :pointer)) (define-crypto-function ("PEM_write_bio_X509" pem-write-x509) :int (bio :pointer) (x509 :pointer)) (define-crypto-function ("PEM_read_bio_X509" pem-read-x509) :pointer ;; all args are :pointers in fact, but they are NULL anyway (bio :pointer) (x509 :int) (callback :int) (passphrase :int)) ;;; EVP (define-crypto-function ("EVP_get_digestbyname" evp-get-digest-by-name) :pointer (name :string)) (define-crypto-function-ex (:vanished "3.0.0") ("EVP_MD_size" evp-md-size) :int (evp :pointer)) (define-crypto-function-ex (:since "3.0.0") ("EVP_MD_get_size" evp-md-get-size) :int (evp :pointer)) ;; GENERAL-NAME types (defconstant +GEN-OTHERNAME+ 0) (defconstant +GEN-EMAIL+ 1) (defconstant +GEN-DNS+ 2) (defconstant +GEN-X400+ 3) (defconstant +GEN-DIRNAME+ 4) (defconstant +GEN-EDIPARTY+ 5) (defconstant +GEN-URI+ 6) (defconstant +GEN-IPADD+ 7) (defconstant +GEN-RID+ 8) (defconstant +v-asn1-octet-string+ 4) (defconstant +v-asn1-utf8string+ 12) (defconstant +v-asn1-printablestring+ 19) (defconstant +v-asn1-teletexstring+ 20) (defconstant +v-asn1-iastring+ 22) (defconstant +v-asn1-universalstring+ 28) (defconstant +v-asn1-bmpstring+ 30) (defconstant +NID-subject-alt-name+ 85) (defconstant +NID-commonName+ 13) (cffi:defcstruct general-name (type :int) (data :pointer)) (define-crypto-function-ex (:vanished "1.1.0") ("sk_value" sk-value) :pointer (stack :pointer) (index :int)) (define-crypto-function-ex (:vanished "1.1.0") ("sk_num" sk-num) :int (stack :pointer)) (define-crypto-function-ex (:since "1.1.0") ("OPENSSL_sk_value" openssl-sk-value) :pointer (stack :pointer) (index :int)) (define-crypto-function-ex (:since "1.1.0") ("OPENSSL_sk_num" openssl-sk-num) :int (stack :pointer)) (declaim (ftype (function (cffi:foreign-pointer fixnum) cffi:foreign-pointer) sk-general-name-value)) (defun sk-general-name-value (names index) (if (and (not (libresslp)) (openssl-is-at-least 1 1)) (openssl-sk-value names index) (sk-value names index))) (declaim (ftype (function (cffi:foreign-pointer) fixnum) sk-general-name-num)) (defun sk-general-name-num (names) (if (and (not (libresslp)) (openssl-is-at-least 1 1)) (openssl-sk-num names) (sk-num names))) (define-crypto-function ("GENERAL_NAMES_free" general-names-free) :void (general-names :pointer)) (define-crypto-function ("ASN1_STRING_data" asn1-string-data) :pointer (asn1-string :pointer)) (define-crypto-function ("ASN1_STRING_length" asn1-string-length) :int (asn1-string :pointer)) (define-crypto-function ("ASN1_STRING_type" asn1-string-type) :int (asn1-string :pointer)) (cffi:defcstruct asn1_string_st (length :int) (type :int) (data :pointer) (flags :long)) (define-crypto-function ("ASN1_TIME_check" asn1-time-check) :int (asn1-string :pointer)) (define-crypto-function ("ASN1_UTCTIME_check" asn1-utctime-check) :int (asn1-string :pointer)) ;; X509 & ASN1 - end (define-ssl-function ("SSL_CTX_set_default_verify_paths" ssl-ctx-set-default-verify-paths) :int (ctx :pointer)) (define-ssl-function-ex (:since "1.1.0") ("SSL_CTX_set_default_verify_dir" ssl-ctx-set-default-verify-dir) :int (ctx :pointer)) (define-ssl-function-ex (:since "1.1.0") ("SSL_CTX_set_default_verify_file" ssl-ctx-set-default-verify-file) :int (ctx :pointer)) (define-crypto-function ("RSA_generate_key" rsa-generate-key) :pointer (num :int) (e :unsigned-long) (callback :pointer) (opt :pointer)) (define-crypto-function ("RSA_free" rsa-free) :void (rsa :pointer)) (define-ssl-function-ex (:vanished "1.1.0") ("SSL_CTX_set_tmp_rsa_callback" ssl-ctx-set-tmp-rsa-callback) :pointer (ctx :pointer) (callback :pointer)) (cffi:defcallback tmp-rsa-callback :pointer ((ssl :pointer) (export-p :int) (key-length :int)) (declare (ignore ssl export-p)) (flet ((rsa-key (length) (rsa-generate-key length +RSA_F4+ (cffi:null-pointer) (cffi:null-pointer)))) (cond ((= key-length 512) (unless *tmp-rsa-key-512* (setf *tmp-rsa-key-512* (rsa-key key-length))) *tmp-rsa-key-512*) ((= key-length 1024) (unless *tmp-rsa-key-1024* (setf *tmp-rsa-key-1024* (rsa-key key-length))) *tmp-rsa-key-1024*) (t (unless *tmp-rsa-key-2048* (setf *tmp-rsa-key-2048* (rsa-key key-length))) *tmp-rsa-key-2048*)))) ;;; Funcall wrapper ;;; (defvar *socket*) (declaim (inline ensure-ssl-funcall)) (defun ensure-ssl-funcall (stream success-test func handle &rest other-args) (loop (let ((ret (let ((*socket* (ssl-stream-socket stream))) ;for Lisp-BIO callbacks (apply func handle other-args)))) (when (funcall success-test ret) (return ret)) (let ((error (ssl-get-error handle ret))) (case error (#.+ssl-error-want-read+ (input-wait stream (ssl-get-fd handle) (ssl-stream-deadline stream))) (#.+ssl-error-want-write+ (output-wait stream (ssl-get-fd handle) (ssl-stream-deadline stream))) (t (ssl-signal-error handle func error ret))))))) (declaim (inline nonblocking-ssl-funcall)) (defun nonblocking-ssl-funcall (stream success-test func handle &rest other-args) (loop (let ((ret (let ((*socket* (ssl-stream-socket stream))) ;for Lisp-BIO callbacks (apply func handle other-args)))) (when (funcall success-test ret) (return ret)) (let ((error (ssl-get-error handle ret))) (case error ((#.+ssl-error-want-read+ #.+ssl-error-want-write+) (return ret)) (t (ssl-signal-error handle func error ret))))))) ;;; Waiting for output to be possible #+clozure-common-lisp (defun milliseconds-until-deadline (deadline stream) (let* ((now (get-internal-real-time))) (if (> now deadline) (error 'ccl::communication-deadline-expired :stream stream) (values (round (- deadline now) (/ internal-time-units-per-second 1000)))))) #+clozure-common-lisp (defun output-wait (stream fd deadline) (unless deadline (setf deadline (stream-deadline (ssl-stream-socket stream)))) (let* ((timeout (if deadline (milliseconds-until-deadline deadline stream) nil))) (multiple-value-bind (win timedout error) (ccl::process-output-wait fd timeout) (unless win (if timedout (error 'ccl::communication-deadline-expired :stream stream) (ccl::stream-io-error stream (- error) "write")))))) (defun seconds-until-deadline (deadline) (/ (- deadline (get-internal-real-time)) internal-time-units-per-second)) #+sbcl (defun output-wait (stream fd deadline) (declare (ignore stream)) (let ((timeout ;; *deadline* is handled by wait-until-fd-usable automatically, ;; but we need to turn a user-specified deadline into a timeout (when deadline (seconds-until-deadline deadline)))) (sb-sys:wait-until-fd-usable fd :output timeout))) #+allegro (eval-when (:compile-top-level :load-top-level :execute) (require :process)) #+allegro (defun output-wait (stream fd deadline) (declare (ignore stream)) (let ((timeout (when deadline (seconds-until-deadline deadline)))) (mp:process-wait-with-timeout "cl+ssl waiting for output" timeout 'excl:write-no-hang-p fd))) #-(or clozure-common-lisp sbcl allegro) (defun output-wait (stream fd deadline) (declare (ignore stream fd deadline)) ;; This situation means that the lisp set our fd to non-blocking mode, ;; and streams.lisp didn't know how to undo that. (warn "cl+ssl::output-wait is not implemented for this lisp, but a non-blocking stream is encountered")) ;;; Waiting for input to be possible #+clozure-common-lisp (defun input-wait (stream fd deadline) (unless deadline (setf deadline (stream-deadline (ssl-stream-socket stream)))) (let* ((timeout (if deadline (milliseconds-until-deadline deadline stream) nil))) (multiple-value-bind (win timedout error) (ccl::process-input-wait fd timeout) (unless win (if timedout (error 'ccl::communication-deadline-expired :stream stream) (ccl::stream-io-error stream (- error) "read")))))) #+sbcl (defun input-wait (stream fd deadline) (declare (ignore stream)) (let ((timeout ;; *deadline* is handled by wait-until-fd-usable automatically, ;; but we need to turn a user-specified deadline into a timeout (when deadline (seconds-until-deadline deadline)))) (sb-sys:wait-until-fd-usable fd :input timeout))) #+allegro (defun input-wait (stream fd deadline) (declare (ignore stream)) (let ((timeout (when deadline (max 0 (seconds-until-deadline deadline))))) (mp:wait-for-input-available fd :timeout timeout :whostate "cl+ssl waiting for input"))) #+lispworks (defun input-wait (stream fd deadline) (declare (ignore fd)) (let* ((timeout (when deadline (max 0 (seconds-until-deadline deadline))))) (system:wait-for-input-streams (list (ssl-stream-socket stream)) :timeout timeout :wait-reason "cl+ssl waiting for input"))) #-(or clozure-common-lisp sbcl allegro lispworks) (defun input-wait (stream fd deadline) (declare (ignore stream fd deadline)) ;; This situation means that the lisp set our fd to non-blocking mode, ;; and streams.lisp didn't know how to undo that. (warn "cl+ssl::input-wait is not implemented for this lisp, but a non-blocking stream is encountered")) ;;; Encrypted PEM files support ;;; ;; based on http://www.openssl.org/docs/ssl/SSL_CTX_set_default_passwd_cb.html (defvar *pem-password* "" "The callback registered with SSL_CTX_set_default_passwd_cb will use this value.") ;; The callback itself (cffi:defcallback pem-password-callback :int ((buf :pointer) (size :int) (rwflag :int) (unused :pointer)) (declare (ignore rwflag unused)) (let* ((password-str (coerce *pem-password* 'base-string)) (tmp (cffi:foreign-string-alloc password-str))) (cffi:foreign-funcall "strncpy" :pointer buf :pointer tmp :int size) (cffi:foreign-string-free tmp) (setf (cffi:mem-ref buf :char (1- size)) 0) (cffi:foreign-funcall "strlen" :pointer buf :int))) ;; The macro to be used by other code to provide password ;; when loading PEM file. (defmacro with-pem-password ((password) &body body) `(let ((*pem-password* (or ,password ""))) ,@body)) ;;; Initialization ;;; (defun init-prng (seed-byte-sequence) (let* ((length (length seed-byte-sequence)) (buf (cffi:make-shareable-byte-vector length))) (dotimes (i length) (setf (elt buf i) (elt seed-byte-sequence i))) (cffi:with-pointer-to-vector-data (ptr buf) (rand-seed ptr length)))) (defun ssl-ctx-set-session-cache-mode (ctx mode) (ssl-ctx-ctrl ctx +SSL_CTRL_SET_SESS_CACHE_MODE+ mode (cffi:null-pointer))) (defun ssl-set-tlsext-host-name (ctx hostname) (ssl-ctrl ctx 55 #|SSL_CTRL_SET_TLSEXT_HOSTNAME|# 0 #|TLSEXT_NAMETYPE_host_name|# hostname)) (defvar *locks*) (defconstant +CRYPTO-LOCK+ 1) (defconstant +CRYPTO-UNLOCK+ 2) (defconstant +CRYPTO-READ+ 4) (defconstant +CRYPTO-WRITE+ 8) ;; zzz as of early 2011, bxthreads is totally broken on SBCL wrt. explicit ;; locking of recursive locks. with-recursive-lock works, but acquire/release ;; don't. Hence we use non-recursize locks here (but can use a recursive ;; lock for the global lock). (cffi:defcallback locking-callback :void ((mode :int) (n :int) (file :pointer) ;; could be (file :string), but we don't use FILE, so avoid the conversion (line :int)) (declare (ignore file line)) ;; (assert (logtest mode (logior +CRYPTO-READ+ +CRYPTO-WRITE+))) (let ((lock (elt *locks* n))) (cond ((logtest mode +CRYPTO-LOCK+) (bt:acquire-lock lock)) ((logtest mode +CRYPTO-UNLOCK+) (bt:release-lock lock)) (t (error "fell through"))))) (defvar *threads* (trivial-garbage:make-weak-hash-table :weakness :key)) (defvar *thread-counter* 0) (defparameter *global-lock* (bordeaux-threads:make-recursive-lock "SSL initialization")) ;; zzz BUG: On a 32-bit system and under non-trivial load, this counter ;; is likely to wrap in less than a year. (cffi:defcallback threadid-callback :unsigned-long () (bordeaux-threads:with-recursive-lock-held (*global-lock*) (let ((self (bt:current-thread))) (or (gethash self *threads*) (setf (gethash self *threads*) (incf *thread-counter*)))))) (defvar *ssl-check-verify-p* :unspecified "DEPRECATED. Use the (MAKE-SSL-CLIENT-STREAM .. :VERIFY ?) to enable/disable verification. MAKE-CONTEXT also allows to enab/disable verification.") (defun default-ssl-method () (if (openssl-is-at-least 1 1) 'tls-method 'ssl-v23-method)) (defun initialize (&key method rand-seed) (when (or (openssl-is-not-even 1 1) ;; Old versions of LibreSSL ;; require this initialization ;; (https://github.com/cl-plus-ssl/cl-plus-ssl/pull/91), ;; new versions keep this API backwards ;; compatible so we can call it too. (libresslp)) (setf *locks* (loop repeat (crypto-num-locks) collect (bt:make-lock))) (crypto-set-locking-callback (cffi:callback locking-callback)) (crypto-set-id-callback (cffi:callback threadid-callback)) (ssl-load-error-strings) (ssl-library-init) ;; However, for OpenSSL_add_all_digests the LibreSSL breaks ;; the backward compatibility by removing the function. ;; https://github.com/cl-plus-ssl/cl-plus-ssl/pull/134 (unless (libresslp) (openssl-add-all-digests))) (setf *bio-is-opaque* ;; (openssl-is-at-least 1 1) - this is not precise in case of LibreSSL, ;; therefore use the following: (not (null (cffi:foreign-symbol-pointer "BIO_get_new_index" :library 'libcrypto))) *lisp-bio-type* (lisp-bio-type) *bio-lisp-method* (make-bio-lisp-method)) (when rand-seed (init-prng rand-seed)) (setf *ssl-check-verify-p* :unspecified) (setf *ssl-global-method* (funcall (or method (default-ssl-method)))) (setf *ssl-global-context* (ssl-ctx-new *ssl-global-method*)) (unless (eql 1 (ssl-ctx-set-default-verify-paths *ssl-global-context*)) (error "ssl-ctx-set-default-verify-paths failed.")) (ssl-ctx-set-session-cache-mode *ssl-global-context* 3) (ssl-ctx-set-default-passwd-cb *ssl-global-context* (cffi:callback pem-password-callback)) (when (or (openssl-is-not-even 1 1) ;; Again, even if newer LibreSSL ;; don't need this call, they keep ;; the API compatibility so we can continue ;; making this call. (libresslp)) (ssl-ctx-set-tmp-rsa-callback *ssl-global-context* (cffi:callback tmp-rsa-callback)))) (defun ensure-initialized (&key method (rand-seed nil)) "In most cases you do *not* need to call this function, because it is called automatically by all other functions. The only reason to call it explicitly is to supply the RAND-SEED parameter. In this case do it before calling any other functions. Just leave the default value for the METHOD parameter. RAND-SEED is an octet sequence to initialize OpenSSL random number generator. On many platforms, including Linux and Windows, it may be left NIL (default), because OpenSSL initializes the random number generator from OS specific service. But for example on Solaris it may be necessary to supply this value. The minimum length required by OpenSSL is 128 bits. See http://www.openssl.org/support/faq.html#USER1 for details. Hint: do not use Common Lisp RANDOM function to generate the RAND-SEED, because the function usually returns predictable values." #+lispworks (check-cl+ssl-symbols) (bordeaux-threads:with-recursive-lock-held (*global-lock*) (unless (ssl-initialized-p) (initialize :method method :rand-seed rand-seed)))) (defun use-certificate-chain-file (certificate-chain-file) "Loads a PEM encoded certificate chain file CERTIFICATE-CHAIN-FILE and adds the chain to global context. The certificates must be sorted starting with the subject's certificate (actual client or server certificate), followed by intermediate CA certificates if applicable, and ending at the highest level (root) CA. Note: the RELOAD function clears the global context and in particular the loaded certificate chain." (ensure-initialized) (ssl-ctx-use-certificate-chain-file *ssl-global-context* certificate-chain-file)) (defun reload () (detect-custom-openssl-installations-if-macos) (unless (member :cl+ssl-foreign-libs-already-loaded *features*) (cffi:use-foreign-library libcrypto) (cffi:load-foreign-library 'libssl)) (setf *ssl-global-context* nil) (setf *ssl-global-method* nil) (setf *tmp-rsa-key-512* nil) (setf *tmp-rsa-key-1024* nil))
47,520
Common Lisp
.lisp
1,158
36.259931
121
0.678641
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
563c0815d66a7454fa54face50c5114d7f129503af13d6cb620b826f801b7dff
42,852
[ -1 ]
42,853
bio.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/bio.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2005 David Lichteblau ;;; Copyright (C) 2021 Tomas Zellerin ([email protected], https://github.com/zellerin) ;;; Copyright (C) 2021 Anton Vodonosov ([email protected], https://github.com/avodonosov) ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package"))) (in-package cl+ssl) (defconstant +BIO_TYPE_SOURCE_SINK+ #x0400) (defconstant +BIO_TYPE_DESCRIPTOR+ #x0100) (defconstant +bio-type-socket+ (logior 5 +BIO_TYPE_SOURCE_SINK+ +BIO_TYPE_DESCRIPTOR+)) (defconstant +BIO_CTRL_EOF+ 2) (defconstant +BIO_CTRL_FLUSH+ 11) (defconstant +BIO_FLAGS_READ+ 1) (defconstant +BIO_FLAGS_WRITE+ 2) (defconstant +BIO_FLAGS_IO_SPECIAL+ 4) (defconstant +BIO_FLAGS_RWS+ (logior +BIO_FLAGS_READ+ +BIO_FLAGS_WRITE+ +BIO_FLAGS_IO_SPECIAL+)) (defconstant +BIO_FLAGS_SHOULD_RETRY+ 8) (defconstant +BIO_FLAGS_IN_EOF+ #x800) (cffi:defcstruct bio-method (type :int) (name :pointer) (bwrite :pointer) (bread :pointer) (bputs :pointer) (bgets :pointer) (ctrl :pointer) (create :pointer) (destroy :pointer) (callback-ctrl :pointer)) (cffi:defcstruct bio (method :pointer) (callback :pointer) (cb-arg :pointer) (init :int) (shutdown :int) (flags :int) (retry-reason :int) (num :int) (ptr :pointer) (next-bio :pointer) (prev-bio :pointer) (references :int) (num-read :unsigned-long) (num-write :unsigned-long) (crypto-ex-data-stack :pointer) (crypto-ex-data-dummy :int)) (defun lisp-bio-type () (or (ignore-errors (logior (bio-new-index) +BIO_TYPE_SOURCE_SINK+)) ;; Old OpenSSL and LibreSSL do not nave BIO_get_new_index, ;; in this case fallback to BIO_TYPE_SOCKET. ;; fixmy: Maybe that's wrong, but presumably still better than some ;; random value here. +bio-type-socket+)) (defun make-bio-lisp-method-slots () (let ((m (cffi:foreign-alloc '(:struct bio-method)))) (setf (cffi:foreign-slot-value m '(:struct bio-method) 'type) *lisp-bio-type*) (macrolet ((slot (name) `(cffi:foreign-slot-value m '(:struct bio-method) ,name))) (setf (slot 'name) (cffi:foreign-string-alloc "lisp")) (setf (slot 'bwrite) (cffi:callback lisp-write)) (setf (slot 'bread) (cffi:callback lisp-read)) (setf (slot 'bputs) (cffi:callback lisp-puts)) (setf (slot 'bgets) (cffi:callback lisp-gets)) (setf (slot 'ctrl) (cffi:callback lisp-ctrl)) (setf (slot 'create) (cffi:callback lisp-create-slots)) (setf (slot 'destroy) (cffi:callback lisp-destroy-slots)) (setf (slot 'callback-ctrl) (cffi:null-pointer))) m)) (defun make-bio-lisp-method-opaque () (let ((m (bio-meth-new *lisp-bio-type* "lisp"))) (bio-set-puts m (cffi:callback lisp-puts)) (bio-set-write m (cffi:callback lisp-write)) (bio-set-read m (cffi:callback lisp-read)) (bio-set-gets m (cffi:callback lisp-gets)) (bio-set-create m (cffi:callback lisp-create-opaque)) (bio-set-destroy m (cffi:callback lisp-destroy-opaque)) (bio-set-ctrl m (cffi:callback lisp-ctrl)) m)) (defun make-bio-lisp-method () (if *bio-is-opaque* (make-bio-lisp-method-opaque) (make-bio-lisp-method-slots))) (defun bio-new-lisp () (unless *bio-lisp-method* (initialize)) (let ((new (bio-new *bio-lisp-method*))) (if (or (null new) (cffi:null-pointer-p new)) (error "Cannot create bio method: ~a" (cl+ssl::err-error-string (cl+ssl::err-get-error) (cffi:null-pointer))) new))) (defun bio-set-flags-slots (bio &rest flags) (setf (cffi:foreign-slot-value bio '(:struct bio) 'flags) (logior (cffi:foreign-slot-value bio '(:struct bio) 'flags) (apply #'logior flags)))) (defun compat-bio-set-flags (bio &rest flags) (if *bio-is-opaque* (bio-set-flags bio (apply #'logior flags)) ;; FFI function since OpenSSL 1.1.0 (apply #'bio-set-flags-slots bio flags))) (defun bio-clear-flags-slots (bio &rest flags) (setf (cffi:foreign-slot-value bio '(:struct bio) 'flags) (logandc2 (cffi:foreign-slot-value bio '(:struct bio) 'flags) (apply #'logior flags)))) (defun compat-bio-clear-flags (bio &rest flags) (if *bio-is-opaque* (bio-clear-flags bio (apply #'logior flags)) ;; FFI function since OpenSSL 1.1.0 (apply #'bio-clear-flags-slots bio flags))) (defun bio-test-flags-slots (bio &rest flags) (logand (cffi:foreign-slot-value bio '(:struct bio) 'flags) (apply #'logior flags))) (defun compat-bio-test-flags (bio &rest flags) (if *bio-is-opaque* (bio-test-flags bio (apply #'logior flags)) ;; FFI function since OpenSSL 1.1.0 (apply #'bio-test-flags-slots bio flags))) (defun clear-retry-flags (bio) (compat-bio-clear-flags bio +BIO_FLAGS_RWS+ +BIO_FLAGS_SHOULD_RETRY+)) (defun set-retry-read (bio) (compat-bio-set-flags bio +BIO_FLAGS_READ+ +BIO_FLAGS_SHOULD_RETRY+)) ;;; Error handling for all the defcallback's: ;;; ;;; We want to avoid non-local exits across C stack, ;;; as CFFI tutorial recommends: ;;; https://common-lisp.net/project/cffi/manual/html_node/Tutorial_002dCallbacks.html. ;;; ;;; In cl+ssl this means the following nested calls: ;;; ;;; 1) Lisp: cl+ssl stream user code -> ;;; 2) C: OpenSSL C functions -> ;;; 3) Lisp: BIO implementation function ;;; signals error and the controls is passed ;;; to (1), without proper C cleanup. ;;; ;;; Therefore our BIO implementation functions catch all unexpected ;;; serious-conditions, arrange for BIO_should_retry ;;; to say "do not retry", and return error status (most often -1). ;;; ;;; We could try to return the real number of bytes read / written - ;;; the documentation of BIO_read and friends just says return byte ;;; number without making any special case for error: ;;; ;;; > (...) return either the amount of data successfully read or ;;; > written (if the return value is positive) or that no data was ;;; > successfully read or written if the result is 0 or -1. If the ;;; > return value is -2 then the operation is not implemented in the ;;; > specific BIO type. The trailing NUL is not included in the length ;;; > returned by BIO_gets(). ;;; ;;; But let's not complicate the implementation, especially taking into ;;; account that we don't know how many bytes the low level ;;; Lisp function has really written before signalling ;;; the condition. Our main goal is to avoid crossing C stack, ;;; and we only consider unexpected errors here. (defparameter *file-name* (cffi:foreign-string-alloc "cl+ssl/src/bio.lisp")) (defparameter *lib-num-for-errors* (if (openssl-is-at-least 1 0 2) (err-get-next-error-library) +err_lib_none+)) (defun put-to-openssl-error-queue (condition) (handler-case (let ((err-msg (format nil "Unexpected serious-condition ~A in the Lisp BIO: ~A" (type-of condition) condition))) (if (openssl-is-at-least 3 0) (progn (err-new) (err-set-debug *file-name* 0 (cffi:null-pointer)) #-cffi-sys::no-foreign-funcall ; because err-set-error ; is a vararg function (err-set-error *lib-num-for-errors* +err_r_internal_error+ "%s" :string err-msg)) (progn (err-put-error *lib-num-for-errors* 0 +err_r_internal_error+ *file-name* 0) #-cffi-sys::no-foreign-funcall ; because err-add-error-data ; is a vararg function (err-add-error-data 1 :string err-msg)))) (serious-condition (c) (warn "~A when saving Lisp BIO error to OpenSSL error queue: ~A" (type-of c) c)))) (cffi:defcallback lisp-write :int ((bio :pointer) (buf :pointer) (n :int)) (handler-case (progn (dotimes (i n) (write-byte (cffi:mem-ref buf :unsigned-char i) *socket*)) (finish-output *socket*) n) (serious-condition (c) (clear-retry-flags bio) (put-to-openssl-error-queue c) -1))) (cffi:defcallback lisp-read :int ((bio :pointer) (buf :pointer) (n :int)) (handler-case (let ((i 0)) (handler-case (progn (clear-retry-flags bio) (loop while (and (< i n) (or *blockp* (listen *socket*))) do (setf (cffi:mem-ref buf :unsigned-char i) (read-byte *socket*)) (incf i)) (when (zerop i) (set-retry-read bio))) (end-of-file () (compat-bio-set-flags bio +BIO_FLAGS_IN_EOF+) ;; now just return the number of bytes read so far )) ;; Old OpenSSL treats zero as EOF and signals an error: ;; "The TLS/SSL connection on handle #<A Foreign Pointer #x7F42DC082880> has been closed (return code: 5)" ;; despite our implementation of (BIO_ctrl ... +BIO_CTRL_EOF+) ;; returns false. ;; (This was observed on openssl-1.1.0j. And ;; on OpenSSL 3 it does not happen). ;; Since both 0 and -1 are allowed by the docs, ;; let's return -1 instead of 0. (if (= 0 i) -1 i)) (serious-condition (c) (clear-retry-flags bio) (put-to-openssl-error-queue c) -1))) (cffi:defcallback lisp-gets :int ((bio :pointer) (buf :pointer) (n :int)) (handler-case (let ((i 0) (max-chars (1- n))) (clear-retry-flags bio) (handler-case (loop with char and exit = nil while (and (< i max-chars) (null exit) (or *blockp* (listen *socket*))) do (setf char (read-byte *socket*) exit (= char 10)) (setf (cffi:mem-ref buf :unsigned-char i) char) (incf i)) (end-of-file () (compat-bio-set-flags bio +BIO_FLAGS_IN_EOF+))) (setf (cffi:mem-ref buf :unsigned-char i) 0) i) (serious-condition (c) (clear-retry-flags bio) (put-to-openssl-error-queue c) -1))) (cffi:defcallback lisp-puts :int ((bio :pointer) (buf :string)) (handler-case (progn (write-line buf (flex:make-flexi-stream *socket* :external-format :ascii)) ;; puts is not specified to return length, but BIO expects it :( (1+ (length buf))) (serious-condition (c) (clear-retry-flags bio) (put-to-openssl-error-queue c) -1))) (cffi:defcallback lisp-ctrl :int ((bio :pointer) (cmd :int) (larg :long) (parg :pointer)) (declare (ignore larg parg)) (cond ((eql cmd +BIO_CTRL_EOF+) (if (zerop (compat-bio-test-flags bio +BIO_FLAGS_IN_EOF+)) 0 1)) ((eql cmd +BIO_CTRL_FLUSH+) 1) (t ;; (warn "lisp-ctrl(~A,~A,~A)" cmd larg parg) 0))) ;;; The create and destroy handlers mostly consist ;;; of setting zero values to some BIO fields, ;;; which seem redundant, because OpenSSl most likely ;;; does this itself. But we follow example of the ;;; standard OpenSSL BIO types implementation. ;;; Like the file_new / file_free here: ;;; https://github.com/openssl/openssl/blob/4ccad35756dfa9df657f3853810101fa9d6ca525/crypto/bio/bss_file.c#L109 (cffi:defcallback lisp-create-slots :int ((bio :pointer)) (handler-case (progn (setf (cffi:foreign-slot-value bio '(:struct bio) 'init) 1) ; the only useful thing? (setf (cffi:foreign-slot-value bio '(:struct bio) 'num) 0) (setf (cffi:foreign-slot-value bio '(:struct bio) 'ptr) (cffi:null-pointer)) (setf (cffi:foreign-slot-value bio '(:struct bio) 'flags) 0) 1) (serious-condition (c) (put-to-openssl-error-queue c) 0))) (cffi:defcallback lisp-create-opaque :int ((bio :pointer)) (handler-case (progn (bio-set-init bio 1) ; the only useful thing? (clear-retry-flags bio) 1) (serious-condition (c) (put-to-openssl-error-queue c) 0))) (cffi:defcallback lisp-destroy-slots :int ((bio :pointer)) (handler-case (cond ((cffi:null-pointer-p bio) 0) (t (setf (cffi:foreign-slot-value bio '(:struct bio) 'init) 0) (setf (cffi:foreign-slot-value bio '(:struct bio) 'flags) 0) 1)) (serious-condition (c) (put-to-openssl-error-queue c) 0))) (cffi:defcallback lisp-destroy-opaque :int ((bio :pointer)) (handler-case (cond ((cffi:null-pointer-p bio) 0) (t (bio-set-init bio 0) (clear-retry-flags bio) 1)) (serious-condition (c) (put-to-openssl-error-queue c) 0))) ;;; Convenience macros (defmacro with-bio-output-to-string ((bio &key (element-type ''character) (transformer '#'code-char)) &body body) "Evaluate BODY with BIO bound to a SSL BIO structure that writes to a Common Lisp string. The string is returned." `(let ((*socket* (flex:make-in-memory-output-stream :element-type ,element-type :transformer ,transformer)) (,bio (bio-new-lisp))) (unwind-protect (progn ,@body) (bio-free ,bio)) (flex:get-output-stream-sequence *socket*))) (defmacro with-bio-input-from-string ((bio string &key (transformer '#'char-code)) &body body) "Evaluate BODY with BIO bound to a SSL BIO structure that reads from a Common Lisp STRING." `(let ((*socket* (flex:make-in-memory-input-stream ,string :transformer ,transformer)) (,bio (bio-new-lisp))) (unwind-protect (progn ,@body) (bio-free ,bio)))) ;; TODO: Refactor dependendies, err-print-error-to-sting is used ;; in conditions.lisp, earlier than it is defined in the bio.lisp. ;; Becuase we can only define it after BIO functionality is implemented. ;; And bio.lisp depends on ffi.lisp, and ffi.lisp depends on conditions.lisp. (defun err-print-errors-to-string () (with-bio-output-to-string (bio) (err-print-errors bio))) (setf *bio-lisp-method* nil) ;force reinit if anything changed here
14,863
Common Lisp
.lisp
362
33.381215
114
0.606044
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e4263bf910df982ae06091ea4b00972f9e9c1f4427d9f1b59d533dc44bd726d1
42,853
[ -1 ]
42,854
context.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/context.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl) (define-condition verify-location-not-found-error (ssl-error) ((location :initarg :location)) (:documentation "Unable to find verify locations") (:report (lambda (condition stream) (format stream "Unable to find verify location. Path: ~A" (slot-value condition 'location))))) (defun validate-verify-location (location) (handler-case (cond ((uiop:file-exists-p location) (values location t)) ((uiop:directory-exists-p location) (values location nil)) (t (error 'verify-location-not-found-error :location location))))) (defun add-verify-locations (ctx locations) (dolist (location locations) (multiple-value-bind (location isfile) (validate-verify-location location) (cffi:with-foreign-strings ((location-ptr location)) (unless (= 1 (cl+ssl::ssl-ctx-load-verify-locations ctx (if isfile location-ptr (cffi:null-pointer)) (if isfile (cffi:null-pointer) location-ptr))) (error 'ssl-error :queue (read-ssl-error-queue) :message (format nil "Unable to load verify location ~A" location))))))) (defun ssl-ctx-set-verify-location (ctx location) (cond ((eq :default location) (unless (= 1 (ssl-ctx-set-default-verify-paths ctx)) (error 'ssl-error-call :queue (read-ssl-error-queue) :message (format nil "Unable to load default verify paths")))) ((eq :default-file location) ;; supported since openssl 1.1.0 (unless (= 1 (ssl-ctx-set-default-verify-file ctx)) (error 'ssl-error-call :queue (read-ssl-error-queue) :message (format nil "Unable to load default verify file")))) ((eq :default-dir location) ;; supported since openssl 1.1.0 (unless (= 1 (ssl-ctx-set-default-verify-dir ctx)) (error 'ssl-error-call :queue (read-ssl-error-queue) :message (format nil "Unable to load default verify dir")))) ((stringp location) (add-verify-locations ctx (list location))) ((pathnamep location) (add-verify-locations ctx (list location))) ((and location (listp location)) (add-verify-locations ctx location)) ;; silently allow NIL as location (location (error "Invalid location ~a" location)))) (alexandria:define-constant +default-cipher-list+ (format nil "ECDHE-RSA-AES256-GCM-SHA384:~ ECDHE-RSA-AES256-SHA384:~ ECDHE-RSA-AES256-SHA:~ ECDHE-RSA-AES128-GCM-SHA256:~ ECDHE-RSA-AES128-SHA256:~ ECDHE-RSA-AES128-SHA:~ ECDHE-RSA-RC4-SHA:~ DHE-RSA-AES256-GCM-SHA384:~ DHE-RSA-AES256-SHA256:~ DHE-RSA-AES256-SHA:~ DHE-RSA-AES128-GCM-SHA256:~ DHE-RSA-AES128-SHA256:~ DHE-RSA-AES128-SHA:~ AES256-GCM-SHA384:~ AES256-SHA256:~ AES256-SHA:~ AES128-GCM-SHA256:~ AES128-SHA256:~ AES128-SHA") :test 'equal) (cffi:defcallback verify-peer-callback :int ((ok :int) (ctx :pointer)) (let ((error-code (x509-store-ctx-get-error ctx))) (unless (= error-code 0) (error 'ssl-error-verify :error-code error-code)) ok)) (defun make-context (&key (method nil method-supplied-p) disabled-protocols (options (list +SSL-OP-ALL+)) min-proto-version (session-cache-mode +ssl-sess-cache-server+) (verify-location :default) (verify-depth 100) (verify-mode +ssl-verify-peer+) (verify-callback nil verify-callback-supplied-p) (cipher-list +default-cipher-list+) (pem-password-callback 'pem-password-callback) certificate-chain-file private-key-file private-key-password (private-key-file-type +ssl-filetype-pem+)) (ensure-initialized) (let ((ctx (ssl-ctx-new (if method-supplied-p method (progn (unless disabled-protocols (setf disabled-protocols (list +SSL-OP-NO-SSLv2+ +SSL-OP-NO-SSLv3+))) (funcall (default-ssl-method))))))) (when (cffi:null-pointer-p ctx) (error 'ssl-error-initialize :reason "Can't create new SSL CTX" :queue (read-ssl-error-queue))) (handler-bind ((error (lambda (_) (declare (ignore _)) (ssl-ctx-free ctx)))) (ssl-ctx-set-options ctx (apply #'logior (append disabled-protocols options))) ;; Older OpenSSL versions might not have this SSL_ctrl call. ;; Having them error out is a sane default - it's better than to keep ;; on running with insecure values. ;; People that _have_ to use much too old OpenSSL versions will ;; have to call MAKE-CONTEXT with :MIN-PROTO-VERSION nil. ;; ;; As an aside: OpenSSL had the "SSL_OP_NO_TLSv1_2" constant since ;; 7409d7ad517 2011-04-29 22:56:51 +0000 ;; so requiring a "new"er OpenSSL to match CL+SSL's defauls shouldn't be a problem. (if min-proto-version (if (zerop (ssl-ctx-set-min-proto-version ctx min-proto-version)) (error "Couldn't set minimum SSL protocol version!"))) (ssl-ctx-set-session-cache-mode ctx session-cache-mode) (ssl-ctx-set-verify-location ctx verify-location) (ssl-ctx-set-verify-depth ctx verify-depth) (ssl-ctx-set-verify ctx verify-mode (if verify-callback (cffi:get-callback verify-callback) (if verify-callback-supplied-p (cffi:null-pointer) (if (= verify-mode +ssl-verify-peer+) (cffi:callback verify-peer-callback) (cffi:null-pointer))))) (ssl-ctx-set-cipher-list ctx cipher-list) (ssl-ctx-set-default-passwd-cb ctx (cffi:get-callback pem-password-callback)) (when certificate-chain-file (ssl-ctx-use-certificate-chain-file ctx certificate-chain-file)) (when private-key-file (with-pem-password (private-key-password) (ssl-ctx-use-privatekey-file ctx private-key-file private-key-file-type))) ctx))) (defun call-with-global-context (context auto-free-p body-fn) (let* ((*ssl-global-context* context)) (unwind-protect (funcall body-fn) (when auto-free-p (ssl-ctx-free context))))) (defmacro with-global-context ((context &key auto-free-p) &body body) "Executes the BODY with *SSL-GLOBAL-CONTEXT* bound to the CONTEXT. If AUTO-FREE-P is true the context is freed using SSL-CTX-FREE before exit. " `(call-with-global-context ,context ,auto-free-p (lambda () ,@body)))
7,498
Common Lisp
.lisp
152
36.75
130
0.57879
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
668838a2d737f8e9ec9e684015c57af32f9b7654c4bdcca4bd5de5b4c42d4cc3
42,854
[ -1 ]
42,855
x509.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/x509.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. (in-package :cl+ssl) #| ASN1 string validation references: - https://github.com/digitalbazaar/forge/blob/909e312878838f46ba6d70e90264650b05eb8bde/js/asn1.js - http://www.obj-sys.com/asn1tutorial/node128.html - https://github.com/deadtrickster/ssl_verify_hostname.erl/blob/master/src/ssl_verify_hostname.erl - https://golang.org/src/encoding/asn1/asn1.go?m=text |# (defgeneric decode-asn1-string (asn1-string type)) (defun copy-bytes-to-lisp-vector (src-ptr vector count) (declare (type (simple-array (unsigned-byte 8)) vector) (type fixnum count) (optimize (safety 0) (debug 0) (speed 3))) (dotimes (i count vector) (setf (aref vector i) (cffi:mem-aref src-ptr :unsigned-char i)))) (defun asn1-string-bytes-vector (asn1-string) (let* ((data (asn1-string-data asn1-string)) (length (asn1-string-length asn1-string)) (vector (cffi:make-shareable-byte-vector length))) (copy-bytes-to-lisp-vector data vector length) vector)) (defun asn1-iastring-char-p (byte) (declare (type (unsigned-byte 8) byte) (optimize (speed 3) (debug 0) (safety 0))) (< byte #x80)) (defun asn1-iastring-p (bytes) (declare (type (simple-array (unsigned-byte 8)) bytes) (optimize (speed 3) (debug 0) (safety 0))) (every #'asn1-iastring-char-p bytes)) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-iastring+))) (let ((bytes (asn1-string-bytes-vector asn1-string))) (if (asn1-iastring-p bytes) (flex:octets-to-string bytes :external-format :ascii) (error 'invalid-asn1-string :type '+v-asn1-iastring+)))) (defun asn1-printable-char-p (byte) (declare (type (unsigned-byte 8) byte) (optimize (speed 3) (debug 0) (safety 0))) (cond ;; a-z ((and (>= byte #.(char-code #\a)) (<= byte #.(char-code #\z))) t) ;; '-/ ((and (>= byte #.(char-code #\')) (<= byte #.(char-code #\/))) t) ;; 0-9 ((and (>= byte #.(char-code #\0)) (<= byte #.(char-code #\9))) t) ;; A-Z ((and (>= byte #.(char-code #\A)) (<= byte #.(char-code #\Z))) t) ;; other ((= byte #.(char-code #\ )) t) ((= byte #.(char-code #\:)) t) ((= byte #.(char-code #\=)) t) ((= byte #.(char-code #\?)) t))) (defun asn1-printable-string-p (bytes) (declare (type (simple-array (unsigned-byte 8)) bytes) (optimize (speed 3) (debug 0) (safety 0))) (every #'asn1-printable-char-p bytes)) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-printablestring+))) (let* ((bytes (asn1-string-bytes-vector asn1-string))) (if (asn1-printable-string-p bytes) (flex:octets-to-string bytes :external-format :ascii) (error 'invalid-asn1-string :type '+v-asn1-printablestring+)))) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-utf8string+))) (let* ((data (asn1-string-data asn1-string)) (length (asn1-string-length asn1-string))) (cffi:foreign-string-to-lisp data :count length :encoding :utf-8))) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-universalstring+))) (if (= 0 (mod (asn1-string-length asn1-string) 4)) ;; cffi sometimes fails here on sbcl? idk why (maybe threading?) ;; fail: Illegal :UTF-32 character starting at position 48... ;; when (length bytes) is 48... ;; so I'm passing :count explicitly (or (ignore-errors (cffi:foreign-string-to-lisp (asn1-string-data asn1-string) :count (asn1-string-length asn1-string) :encoding :utf-32)) (error 'invalid-asn1-string :type '+v-asn1-universalstring+)) (error 'invalid-asn1-string :type '+v-asn1-universalstring+))) (defun asn1-teletex-char-p (byte) (declare (type (unsigned-byte 8) byte) (optimize (speed 3) (debug 0) (safety 0))) (and (>= byte #x20) (< byte #x80))) (defun asn1-teletex-string-p (bytes) (declare (type (simple-array (unsigned-byte 8)) bytes) (optimize (speed 3) (debug 0) (safety 0))) (every #'asn1-teletex-char-p bytes)) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-teletexstring+))) (let ((bytes (asn1-string-bytes-vector asn1-string))) (if (asn1-teletex-string-p bytes) (flex:octets-to-string bytes :external-format :ascii) (error 'invalid-asn1-string :type '+v-asn1-teletexstring+)))) (defmethod decode-asn1-string (asn1-string (type (eql +v-asn1-bmpstring+))) (if (= 0 (mod (asn1-string-length asn1-string) 2)) (or (ignore-errors (cffi:foreign-string-to-lisp (asn1-string-data asn1-string) :count (asn1-string-length asn1-string) :encoding :utf-16/be)) (error 'invalid-asn1-string :type '+v-asn1-bmpstring+)) (error 'invalid-asn1-string :type '+v-asn1-bmpstring+))) ;; TODO: respect asn1-string type (defun try-get-asn1-string-data (asn1-string allowed-types) (let ((type (asn1-string-type asn1-string))) (assert (member (asn1-string-type asn1-string) allowed-types) nil "Invalid asn1 string type") (decode-asn1-string asn1-string type))) ;; ASN1 Times are represented with ASN1 Strings (defun decode-asn1-time (asn1-time) (when (zerop (asn1-time-check asn1-time)) (error "asn1-time is not a syntactically valid ASN1 UTCTime")) (let ((time-string (flex:octets-to-string (asn1-string-bytes-vector asn1-time) :external-format :ascii))) (let* ((utctime-p (= 1 (asn1-utctime-check asn1-time))) (year-len (if utctime-p 2 4)) (year-part (parse-integer (subseq time-string 0 year-len))) (year (if utctime-p (if (>= year-part 50) (+ 1900 year-part) (+ 2000 year-part)) year-part))) (flet ((get-element-after-year (position) (parse-integer (subseq time-string (+ position year-len) (+ position year-len 2))))) (let ((month (get-element-after-year 0)) (day (get-element-after-year 2)) (hour (get-element-after-year 4)) (minute (get-element-after-year 6)) (second (get-element-after-year 8))) (encode-universal-time second minute hour day month year 0)))))) (defun slurp-stream (stream) "Returns a sequence containing the STREAM bytes; the sequence is created by CFFI:MAKE-SHAREABLE-BYTE-VECTOR, therefore it can safely be passed to CFFI:WITH-POINTER-TO-VECTOR-DATA." (let ((seq (cffi:make-shareable-byte-vector (file-length stream)))) (read-sequence seq stream) seq)) (defgeneric decode-certificate (format bytes) (:documentation "The BYTES must be created by CFFI:MAKE-SHAREABLE-BYTE-VECTOR (because we are going to pass them to CFFI:WITH-POINTER-TO-VECTOR-DATA)")) (defmethod decode-certificate ((format (eql :der)) bytes) (cffi:with-pointer-to-vector-data (buf* bytes) (cffi:with-foreign-object (buf** :pointer) (setf (cffi:mem-ref buf** :pointer) buf*) (let ((cert (d2i-x509 (cffi:null-pointer) buf** (length bytes)))) (when (cffi:null-pointer-p cert) (error 'ssl-error-call :message "d2i-X509 failed" :queue (read-ssl-error-queue))) cert)))) (defun cert-format-from-path (path) ;; or match "pem" type too and raise unknown format error? (if (equal "der" (pathname-type path)) :der :pem)) (defun decode-certificate-from-file (path &key format) (let ((bytes (with-open-file (stream path :element-type '(unsigned-byte 8)) (slurp-stream stream))) (format (or format (cert-format-from-path path)))) (decode-certificate format bytes))) (defun certificate-alt-names (cert) #| * The return value is the decoded extension or NULL on * error. The actual error can have several different causes, * the value of *crit reflects the cause: * >= 0, extension found but not decoded (reflects critical value). * -1 extension not found. * -2 extension occurs more than once. |# (cffi:with-foreign-object (crit* :int) (let ((result (x509-get-ext-d2i cert +NID-subject-alt-name+ crit* (cffi:null-pointer)))) (if (cffi:null-pointer-p result) (let ((crit (cffi:mem-ref crit* :int))) (cond ((>= crit 0) (error "X509_get_ext_d2i: subject-alt-name extension decoding error")) ((= crit -1) ;; extension not found, return NULL result) ((= crit -2) (error "X509_get_ext_d2i: subject-alt-name extension occurs more than once")))) result)))) (defun certificate-dns-alt-names (cert) (let ((altnames (certificate-alt-names cert))) (unless (cffi:null-pointer-p altnames) (unwind-protect (flet ((alt-name-to-string (alt-name) (cffi:with-foreign-slots ((type data) alt-name (:struct general-name)) (case type (#. +GEN-IPADD+ (let ((address (asn1-string-bytes-vector data))) (usocket:host-to-hostname address))) (#. +GEN-DNS+ (or (try-get-asn1-string-data data '(#. +v-asn1-iastring+)) (error "Malformed certificate: possibly NULL in dns-alt-name"))))))) (let ((altnames-count (sk-general-name-num altnames))) (loop for i from 0 below altnames-count as alt-name = (sk-general-name-value altnames i) collect (alt-name-to-string alt-name)))) (general-names-free altnames))))) (defun certificate-subject-common-names (cert) (let ((i -1) (subject-name (x509-get-subject-name cert))) (when (cffi:null-pointer-p subject-name) (error "X509_get_subject_name returned NULL")) (flet ((extract-cn () (setf i (x509-name-get-index-by-nid subject-name +NID-commonName+ i)) (when (>= i 0) (let* ((entry (x509-name-get-entry subject-name i))) (when (cffi:null-pointer-p entry) (error "X509_NAME_get_entry returned NULL")) (let ((entry-data (x509-name-entry-get-data entry))) (when (cffi:null-pointer-p entry-data) (error "X509_NAME_ENTRY_get_data returned NULL")) (try-get-asn1-string-data entry-data '(#.+v-asn1-utf8string+ #.+v-asn1-bmpstring+ #.+v-asn1-printablestring+ #.+v-asn1-universalstring+ #.+v-asn1-teletexstring+))))))) (loop as cn = (extract-cn) if cn collect cn if (not cn) do (loop-finish))))) (defun certificate-not-after-time (certificate) "Returns a universal-time representing the time after which the certificate is not valid." (when (or (openssl-is-not-even 1 1 0) (libresslp)) (error "certificate-not-after-time currently requires version OpenSSL 1.1.0 or newer")) (let ((asn1-time (x509-get0-not-after certificate))) (when (cffi:null-pointer-p asn1-time) (error "X509_get0_notAfter returned NULL")) (decode-asn1-time asn1-time))) (defun certificate-not-before-time (certificate) "Returns a universal-time representing the time before which the certificate is not valid." (when (or (openssl-is-not-even 1 1 0) (libresslp)) (error "certificate-not-before-time currently requires version OpenSSL 1.1.0 or newer")) (let ((asn1-time (x509-get0-not-before certificate))) (when (cffi:null-pointer-p asn1-time) (error "X509_get0_notBefore returned NULL")) (decode-asn1-time asn1-time))) (defun certificate-fingerprint (certificate &optional (algorithm :sha1)) "Return the fingerprint of CERTIFICATE as a byte-vector. ALGORITHM is a string designator for the digest algorithm to use (it defaults to SHA-1)." (ensure-initialized) (let ((evp (evp-get-digest-by-name (string algorithm)))) (when (cffi:null-pointer-p evp) (error 'ssl-error-call :message (format nil "unknown digest algorithm ~A" algorithm) :queue (read-ssl-error-queue))) (let* ((size (funcall (if (openssl-is-at-least 3 0 0) 'evp-md-get-size 'evp-md-size) evp)) (fingerprint (cffi:make-shareable-byte-vector size))) (cffi:with-pointer-to-vector-data (buf fingerprint) (unless (= 1 (x509-digest certificate evp buf (cffi:null-pointer))) (error 'ssl-error-call :message "failed to compute fingerprint of certificate" :queue (read-ssl-error-queue)))) fingerprint))) (defun x509-cert-from-pem (pem) (with-bio-input-from-string (bio pem) (pem-read-x509 bio 0 0 0))) (defun certificate-pem (x509) (with-bio-output-to-string (bio) ;; man PEM_write_bio_X509: ;; The write routines return 1 for success or 0 for failure. (unless (= 1 (pem-write-x509 bio x509)) (error "X509 cert cant be printed: ~s" (cl+ssl::err-error-string (cl+ssl::err-get-error) (cffi:null-pointer))))))
13,840
Common Lisp
.lisp
290
38.5
147
0.604809
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
1414af3c2e76ed2a0ca97c4e39c5961627c64bc38d4e171e6e3c453cab87a7e8
42,855
[ -1 ]
42,856
reload.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/reload.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) 2001, 2003 Eric Marsden ;;; Copyright (C) 2005 David Lichteblau ;;; "the conditions and ENSURE-SSL-FUNCALL are by Jochen Schmidt." ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. ;;; We do this in an extra file so that it happens ;;; - before ssl.lisp is loaded, which needs the library at compilation ;;; time on some implemenations ;;; - but not every time ffi.lisp is re-loaded as would happen if we ;;; put this directly into ffi.lisp #+xcvb (module (:depends-on ("package"))) (in-package :cl+ssl) ;; The default OS-X libssl seems have had insufficient crypto algos ;; (missing TLSv1_[1,2]_XXX methods, ;; see https://github.com/cl-plus-ssl/cl-plus-ssl/issues/56) ;; so first try to load possible custom installations of libssl. ;; However, macOS can crash the process if we try to load ;; an unexisting path, see ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/138 ;; and the discussion in ;; https://github.com/cl-plus-ssl/cl-plus-ssl/issues/114. ;; Therefore we first detect the presence of custom installations, ;; remember them as special *features* flags, which we then use ;; as conditions in the CFFI library definitions. (defun detect-macos-custom-openssl-installations () (dolist (dir-feature '(("/opt/local/lib/" :cl+ssl-macports-found) ("/sw/lib/" :cl+ssl-fink-found) ("/usr/local/opt/openssl/lib/" :cl+ssl-homebrew-found) ("/opt/homebrew/opt/openssl/lib/" :cl+ssl-homebrew-arm64-found) ("/usr/local/lib/" :cl+ssl-personalized-install-found))) (destructuring-bind (dir feature) dir-feature (if (and (probe-file (concatenate 'string dir "libssl.dylib")) (probe-file (concatenate 'string dir "libcrypto.dylib"))) (pushnew feature *features*) (setf *features* (remove feature *features*)))))) (defun detect-custom-openssl-installations-if-macos () ;; Instead of a read-time conditional we use ;; a run-time check, so that it works even ;; for compiled code or images built on another ;; platform and then reloaded on macOS. (when (member :darwin *features*) (detect-macos-custom-openssl-installations))) (detect-custom-openssl-installations-if-macos) #| A manual test that I used on Linux for the above macOS OpenSSL custom installation detection code. sudo mkdir -p /sw/lib sudo touch /sw/lib/libssl.dylib /sw/lib/libcrypto.dylib sudo touch /usr/local/lib/libcrypto.dylib /usr/local/lib/libssl.dylib (detect-macos-custom-openssl-installations) (remove-if-not (lambda (f) (search "cl+ssl" (string-downcase f))) *features*) sudo rm -rf /sw/ sudo rm /usr/local/lib/libcrypto.dylib /usr/local/lib/libssl.dylib |# ;; Windows builds have been naming librypto and libssl DLLs ;; in several different ways: ;; ;; - libeay32.dll, libssl32.dll ;; - libeay32.dll, ssleay32.dll ;; ;; Note, the above names were used both for 32 and 64 -bit versions. ;; ;; - libcrypto-1_1-x64.dll, libssl-1_1-x64.dll ;; ;; The above are used for 64-bit only. ;; ;; - libcrypto-1_1.dll, libssl-1_1.dll ;; ;; These are 32-bit only. (unless cl+ssl/config::*libcrypto-override* (cffi:define-foreign-library libcrypto (:windows (:or #+(and windows x86-64) "libcrypto-1_1-x64.dll" #+(and windows x86) "libcrypto-1_1.dll" "libeay32.dll")) ;; Unlike some other systems, OpenBSD linker, ;; when passed library name without versions at the end, ;; will locate the library with highest major.minor version, ;; so we can just use just "libssl.so". ;; More info at https://github.com/cl-plus-ssl/cl-plus-ssl/pull/2. (:openbsd "libcrypto.so") ((:and :darwin :cl+ssl-macports-found) "/opt/local/lib/libcrypto.dylib") ((:and :darwin :cl+ssl-fink-found) "/sw/lib/libcrypto.dylib") ((:and :darwin :cl+ssl-homebrew-found) "/usr/local/opt/openssl/lib/libcrypto.dylib") ((:and :darwin :cl+ssl-homebrew-arm64-found) "/opt/homebrew/opt/openssl/lib/libcrypto.dylib") ((:and :darwin :cl+ssl-personalized-install-found) "/usr/local/lib/libcrypto.dylib") (:darwin (:or ;; System-provided libraries. Must be loaded from files with ;; names that include version explicitly, instead of any ;; versionless symlink file. Otherwise macOS crushes the ;; process (starting from macOS > 10.15 that was just a ;; warning, and finally macOS >= 11 crashes the process with a ;; fatal error) Please note that in macOS >= 11.0, these paths ;; may not exist in the file system anymore, but trying to ;; load them via dlopen will work. This is because macOS ships ;; all system-provided libraries as a single dyld_shared_cache ;; bundle. "/usr/lib/libcrypto.46.dylib" "/usr/lib/libcrypto.44.dylib" "/usr/lib/libcrypto.42.dylib" "/usr/lib/libcrypto.41.dylib" "/usr/lib/libcrypto.35.dylib" ;; The default old system libcrypto, versionless file name, ;; which may have insufficient crypto and can cause process ;; crash on macOS >= 11. Currently we are protected from the ;; crash by the presence of the versioned paths above, but in ;; a few years, when those versions are not available anymore, ;; the crash may re-appear. So eventually we will need to ;; delete the unversioned paths. Keeping them for a while for ;; compatibility. See ;; https://github.com/cl-plus-ssl/cl-plus-ssl/pull/115 "libcrypto.dylib" "/usr/lib/libcrypto.dylib")) ((and :unix (not :cygwin)) (:or "libcrypto.so.1.1" "libcrypto.so.1.0.0" "libcrypto.so.3" "libcrypto.so")) (:cygwin (:or "cygcrypto-1.1.dll" "cygcrypto-1.0.0.dll")))) (unless cl+ssl/config::*libssl-override* (cffi:define-foreign-library libssl (:windows (:or #+(and windows x86-64) "libssl-1_1-x64.dll" #+(and windows x86) "libssl-1_1.dll" "libssl32.dll" "ssleay32.dll")) ((:and :darwin :cl+ssl-macports-found) "/opt/local/lib/libssl.dylib") ((:and :darwin :cl+ssl-fink-found) "/sw/lib/libssl.dylib") ((:and :darwin :cl+ssl-homebrew-found) "/usr/local/opt/openssl/lib/libssl.dylib") ((:and :darwin :cl+ssl-homebrew-arm64-found) "/opt/homebrew/opt/openssl/lib/libssl.dylib") ((:and :darwin :cl+ssl-personalized-install-found) "/usr/local/lib/libssl.dylib") (:darwin (:or ;; System-provided libraries, with version in the file name. ;; See the comment for the libcryto equivalents above. "/usr/lib/libssl.48.dylib" "/usr/lib/libssl.46.dylib" "/usr/lib/libssl.44.dylib" "/usr/lib/libssl.43.dylib" "/usr/lib/libssl.35.dylib" ;; Default system libssl, versionless file name. ;; See the coment for the corresponding libcrypto. "libssl.dylib" "/usr/lib/libssl.dylib")) (:solaris (:or "/lib/64/libssl.so" "libssl.so.0.9.8" "libssl.so" "libssl.so.4")) ;; Unlike some other systems, OpenBSD linker, ;; when passed library name without versions at the end, ;; will locate the library with highest major.minor version, ;; so we can just use just "libssl.so". ;; More info at https://github.com/cl-plus-ssl/cl-plus-ssl/pull/2. (:openbsd "libssl.so") ((and :unix (not :cygwin)) (:or "libssl.so.1.1" "libssl.so.1.0.2m" "libssl.so.1.0.2k" "libssl.so.1.0.2" "libssl.so.1.0.1l" "libssl.so.1.0.1j" "libssl.so.1.0.1f" "libssl.so.1.0.1e" "libssl.so.1.0.1" "libssl.so.1.0.0q" "libssl.so.1.0.0" "libssl.so.0.9.8ze" "libssl.so.0.9.8" "libssl.so.10" "libssl.so.4" "libssl.so.3" "libssl.so")) (:cygwin (:or "cygssl-1.1.dll" "cygssl-1.0.0.dll")) (t (:default "libssl3")))) (unless (member :cl+ssl-foreign-libs-already-loaded *features*) (cffi:use-foreign-library libcrypto) (cffi:use-foreign-library libssl))
9,135
Common Lisp
.lisp
173
41.520231
111
0.592236
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
d772b05d9262620b4bf84765ddf839a57adc5aab1957b0550a678d54ac05f593
42,856
[ -1 ]
42,857
ffi-buffer-all.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/src/ffi-buffer-all.lisp
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*- ;;; ;;; Copyright (C) contributors as per cl+ssl git history ;;; ;;; See LICENSE for details. #+xcvb (module (:depends-on ("package"))) (in-package :cl+ssl) (declaim (inline make-buffer buffer-length buffer-elt set-buffer-elt s/b-replace b/s-replace))
398
Common Lisp
.lisp
15
23.266667
112
0.66313
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e2cf627b2c2ace09af0453b8e37f94d9e327225d1e42d7ad2cb00b435778e5df
42,857
[ -1 ]
42,858
test-gen-matrix.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/.github/workflows/test-gen-matrix.lisp
;; TODO: enable CLISP after # https://github.com/cl-plus-ssl/cl-plus-ssl/issues/163 is fixed (flet ((format-test-step (lisp openssl lib-load-mode) (format t " - run: |~%") (format t " LISP=~A OPENSSL=~A BITS=64 LIB_LOAD_MODE=~A docker-home/cl-plus-ssl/.github/workflows/test.sh~%" lisp openssl lib-load-mode) ;; Is 2 mins enough? (format t " timeout-minutes: 2~%") (format t " if: success() || failure()~%") ) (format-retrying-test-step (lisp openssl lib-load-mode) ;; Note the `< /dev/null` at the end of the cmd-line. ;; This is needed to prevent CCL to hang waiting ;; for user input when CCL Kernel Debugger is entered ;; upon unhandled exception. ;; The standard Guthub Actions `run` step closes the ;; stdin of the child shell process automatically. ;; But the nick-fields/retry step keeps it open, ;; so we need this workaround. ;; Reported this as a bug: https://github.com/nick-fields/retry/issues/98 (let ((cmd-line (format nil "LISP=~A OPENSSL=~A BITS=64 LIB_LOAD_MODE=~A docker-home/cl-plus-ssl/.github/workflows/test.sh < /dev/null" lisp openssl lib-load-mode))) (format t " - uses: nick-fields/[email protected]~%") (format t " name: Run with retries ~A~%" cmd-line) (format t " with:~%") (format t " command: |~%") (format t " ~A~%" cmd-line) ;; Is 2 mins enough? Usually the first execution, which is the longest ;; due to Quicklisp download of dependencies and compilation, ;; takes around 55 sec. (format t " timeout_minutes: 2~%") (format t " max_attempts: 3~%") ;; don't hide timeouts (format t " retry_on: error~%") ;; don't hide error situations other than the known crashes (format t " retry_on_exit_code: 137~%") (format t " if: success() || failure()~%")))) (dolist (lib-load-mode '("new" "old")) (dolist (openssl '( ;; newest releases "openssl-3.0.4" "openssl-1.1.1p" "libressl-3.5.3" ;; oldest releaes "openssl-0.9.8zh" "libressl-2.2.7" ;; the rest "openssl-1.1.0j" "openssl-1.0.2q" "openssl-1.0.0s" "libressl-3.5.3" "libressl-3.0.1" "libressl-2.8.3" "libressl-2.6.5" "libressl-2.5.5" )) (dolist (lisp '("sbcl" "ccl" "abcl")) (unless (and (string= lisp "abcl") (string= lib-load-mode "old")) ;; TODO: COVERALLS=true for SBCL on the laest version of OpenSSL and the latest LibreSSL ;; after this cl-coveralls issue is fixed: https://github.com/fukamachi/cl-coveralls/issues/14 ;; TODO: repeat CCL test on the latest OpenSSL with READTABLE_CASE_INVERT=1 (if (string= lisp "ccl") ;; because of https://github.com/Clozure/ccl/issues/85 (format-retrying-test-step lisp openssl lib-load-mode) (format-test-step lisp openssl lib-load-mode)) )))))
3,575
Common Lisp
.lisp
66
39.590909
144
0.507279
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
d144a091fe3f82fbec689fb456faebc5c35d554b076a036c70d02a3fe067385b
42,858
[ -1 ]
42,859
api-doc.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl+ssl-20221106-git/.github/workflows/api-doc.lisp
(pushnew "/home/cl/package-doc-dump/" asdf:*central-registry* :test #'equal) (ql:quickload "package-doc-dump") (pushnew "/home/cl/cl-plus-ssl/" asdf:*central-registry* :test #'equal) (ql:quickload "cl+ssl") ;; make sure we load the local version, ;; not the one coming with Quicklisp (assert (string= "/home/cl/cl-plus-ssl/src/package.lisp" (namestring (asdf:system-relative-pathname "cl+ssl" "src/package.lisp")))) (package-doc-dump:dump-html "cl+ssl" (asdf:system-relative-pathname "cl+ssl" "src/package.lisp") ;; Remove the implementation of cl+ssl:stream-fd, ;; like on CCL `stream-fd ((stream ccl::basic-stream))`, ;; so only the generic function reamins. :doc-node-filter (lambda (doc-node) (not (and (typep doc-node 'docparser:method-node) (string-equal (docparser:node-name doc-node) "stream-fd")))) :output-file "/home/cl/cl-plus-ssl-api.html")
1,408
Common Lisp
.lisp
22
37.818182
101
0.444685
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
1495a1c11deca9ab7b5a1bc7e4b6feabb00badbae9c3e6974a0b0c94ad052217
42,859
[ -1 ]
42,860
cl-cookie.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl-cookie-20220707-git/src/cl-cookie.lisp
(in-package :cl-user) (defpackage cl-cookie (:nicknames :cookie) (:use :cl :proc-parse) (:import-from :quri :cookie-domain-p) (:import-from :local-time :today :timestamp-century :timestamp-to-universal :universal-to-timestamp :format-timestring :encode-timestamp :*abbreviated-subzone-name->timezone-list* :reread-timezone-repository :timezone-subzones :subzone-abbrev :subzone-offset :+gmt-zone+) (:import-from :alexandria :ensure-cons :starts-with-subseq) (:export :parse-set-cookie-header :write-cookie-header :write-set-cookie-header :cookie :make-cookie :cookie= :cookie-equal :cookie-name :cookie-value :cookie-expires :cookie-path :cookie-domain :cookie-secure-p :cookie-httponly-p :cookie-origin-host :cookie-jar :make-cookie-jar :cookie-jar-cookies :cookie-jar-host-cookies :merge-cookies)) (in-package :cl-cookie) (defstruct cookie name value expires path domain secure-p httponly-p origin-host) (defstruct cookie-jar cookies) (defun cookie= (cookie1 cookie2) (and (string= (cookie-name cookie1) (cookie-name cookie2)) (if (cookie-domain cookie1) (equalp (cookie-domain cookie1) (cookie-domain cookie2)) (equalp (cookie-origin-host cookie1) (cookie-origin-host cookie2))) (equal (cookie-path cookie1) (cookie-path cookie2)))) (defun cookie-equal (cookie1 cookie2) (and (cookie= cookie1 cookie2) (eq (cookie-secure-p cookie1) (cookie-secure-p cookie2)) (eq (cookie-httponly-p cookie1) (cookie-httponly-p cookie2)))) (defun expired-cookie-p (cookie) (and (cookie-expires cookie) (< (cookie-expires cookie) (get-universal-time)))) (defun delete-old-cookies (cookie-jar) (setf (cookie-jar-cookies cookie-jar) (delete-if #'expired-cookie-p (cookie-jar-cookies cookie-jar)))) (defun match-cookie-path (request-path cookie-path) (flet ((last-char (str) (aref str (1- (length str))))) (when (= 0 (length request-path)) (setf request-path "/")) (when (= 0 (length cookie-path)) (setf cookie-path "/")) (or (string= request-path cookie-path) (and (starts-with-subseq cookie-path request-path) (or (char= (last-char cookie-path) #\/) (char= (aref request-path (length cookie-path)) #\/)))))) (defun match-cookie (cookie host path &key securep) (and (if (cookie-secure-p cookie) securep t) (match-cookie-path path (cookie-path cookie)) (if (cookie-domain cookie) (cookie-domain-p host (cookie-domain cookie)) (equalp host (cookie-origin-host cookie))))) (defun cookie-jar-host-cookies (cookie-jar host path &key securep) (delete-old-cookies cookie-jar) (remove-if-not (lambda (cookie) (match-cookie cookie host path :securep securep)) (cookie-jar-cookies cookie-jar))) (defun write-cookie-header (cookies &optional stream) (labels ((write-cookie (cookie s) (format s "~A=~A" (cookie-name cookie) (cookie-value cookie))) (main (cookies stream) (write-cookie (pop cookies) stream) (dolist (cookie cookies) (write-string "; " stream) (write-cookie cookie stream)))) (when cookies (if stream (main (ensure-cons cookies) stream) (with-output-to-string (s) (main (ensure-cons cookies) s)))))) (defparameter +set-cookie-date-format+ '(:short-weekday ", " (:day 2) #\space :short-month #\space (:year 4) #\space (:hour 2) #\: (:min 2) #\: (:sec 2) #\space "GMT") "The date format used in RFC 6265. For example: Wed, 09 Jun 2021 10:18:14 GMT.") (defun write-set-cookie-header (cookie &optional stream) (labels ((format-cookie-date (universal-time s) (when universal-time (format-timestring s (universal-to-timestamp universal-time) :format +set-cookie-date-format+ :timezone local-time:+gmt-zone+)))) (format stream "~A=~A~@[; Expires=~A~]~@[; Path=~A~]~@[; Domain=~A~]~:[~;; Secure~]~:[~;; HttpOnly~]" (cookie-name cookie) (cookie-value cookie) (format-cookie-date (cookie-expires cookie) stream) (cookie-path cookie) (cookie-domain cookie) (cookie-secure-p cookie) (cookie-httponly-p cookie)))) (defun merge-cookies (cookie-jar cookies) (setf (cookie-jar-cookies cookie-jar) (delete-duplicates (nconc (cookie-jar-cookies cookie-jar) cookies) :test #'cookie=))) (define-condition invalid-set-cookie (error) ((header :initarg :header)) (:report (lambda (condition stream) (format stream "Invalid Set-Cookie header: ~S" (slot-value condition 'header))))) (define-condition invalid-expires-date (error) ((expires :initarg :expires)) (:report (lambda (condition stream) (format stream "Invalid expires date: ~S. Ignoring." (slot-value condition 'expires))))) (defun integer-char-p (char) (char<= #\0 char #\9)) (defun get-tz-offset (tz-abbrev) (symbol-macrolet ((timezones local-time::*abbreviated-subzone-name->timezone-list*)) (let* ((tz (gethash tz-abbrev timezones nil)) (tz (if tz (car tz) (when (zerop (hash-table-count timezones)) (local-time::reread-timezone-repository :timezone-repository (asdf:system-relative-pathname :local-time #P"zoneinfo/")) (first (gethash tz-abbrev timezones nil)))))) (when tz (loop for sub across (local-time::timezone-subzones tz) when (equal tz-abbrev (local-time::subzone-abbrev sub)) do (return (local-time::subzone-offset sub))))))) (defparameter *current-century-offset* (* (1- (timestamp-century (today))) 100)) (defun parse-cookie-date (cookie-date) (let (year month day hour min sec offset) (handler-case (with-vector-parsing (cookie-date) (labels ((parse-month () (if (integer-char-p (current)) (parse-int) (match-case ("Jan" (match? "uary") 1) ("Feb" (match? "ruary") 2) ("Mar" (match? "ch") 3) ("Apr" (match? "il") 4) ("May" 5) ("Jun" (match? "e") 6) ("Jul" (match? "y") 7) ("Aug" (match? "ust") 8) ("Sep" (match? "tember") 9) ("Oct" (match? "ober") 10) ("Nov" (match? "ember") 11) ("Dec" (match? "ember") 12)))) (parse-int () (bind (int (skip-while integer-char-p)) (parse-integer int)))) (skip? #\") (match-case ("Sun" (match? "day")) ("Mon" (match? "day")) ("Tue" (match? "sday")) ("Wed" (match? "nesday")) ("Thu" (match? "rsday")) ("Fri" (match? "day")) ("Sat" (match? "urday"))) (skip? #\,) (skip #\Space) (if (integer-char-p (current)) (progn (setq day (parse-int)) (skip #\Space #\-) (setq month (parse-month)) (skip #\Space #\-) (setq year (parse-int)) (skip #\Space) (setq hour (parse-int)) (skip #\:) (setq min (parse-int)) (skip #\:) (setq sec (parse-int))) (progn (setq month (parse-month)) (skip #\Space #\-) (setq day (parse-int)) (skip #\Space) (setq hour (parse-int)) (skip #\:) (setq min (parse-int)) (skip #\:) (setq sec (parse-int)) (skip #\Space) (setq year (parse-int)))) (skip #\Space) (bind (tz-abbrev (skip-while alpha-char-p)) (setq offset (get-tz-offset tz-abbrev)) (skip? #\") ;; Shorthand year, default to current century (when (< year 100) (incf year *current-century-offset*)) (return-from parse-cookie-date (local-time:timestamp-to-universal (local-time:encode-timestamp 0 sec min hour day month year :timezone local-time:+gmt-zone+ :offset offset)))))) (error () (error 'invalid-expires-date :expires cookie-date))))) (defun parse-set-cookie-header (set-cookie-string origin-host origin-path) (check-type origin-host string) (let ((cookie (make-cookie :origin-host origin-host :path origin-path))) (handler-case (with-vector-parsing (set-cookie-string) (bind (name (skip+ (not #\=))) (setf (cookie-name cookie) name)) (skip #\=) (bind (value (skip* (not #\;))) (setf (cookie-value cookie) value)) (skip #\;) (loop (skip* #\Space) (match-i-case ("expires" (skip #\=) ;; Assume there're both the Max-Age and the Expires attribute if cookie-expires has already set. ;; In that case, just ignores Expires header. (if (cookie-expires cookie) (skip* (not #\;)) (bind (expires (skip* (not #\;))) (setf (cookie-expires cookie) (parse-cookie-date expires))))) ("max-age" (skip #\=) (bind (max-age (skip* (not #\;))) (setf (cookie-expires cookie) (+ (get-universal-time) (parse-integer max-age))))) ("path" (skip #\=) (bind (path (skip* (not #\;))) (setf (cookie-path cookie) path))) ("domain" (skip #\=) (bind (domain (skip* (not #\;))) (setf (cookie-domain cookie) domain))) ("secure" (setf (cookie-secure-p cookie) t)) ("httponly" (setf (cookie-httponly-p cookie) t)) (otherwise ;; Ignore unknown attributes (skip* (not #\=)) (skip #\=) (skip* (not #\;)))) (skip? #\;))) (match-failed () (error 'invalid-set-cookie :header set-cookie-string)) (invalid-expires-date (e) (warn (princ-to-string e)) (return-from parse-set-cookie-header nil))) cookie))
11,683
Common Lisp
.lisp
286
27.702797
120
0.500967
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
38f806d8d3b17d97accff0b3e81ed5ec81ee5143f4228df6bd5cd9f0a125dd1e
42,860
[ -1 ]
42,861
cl-cookie.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/cl-cookie-20220707-git/t/cl-cookie.lisp
(in-package :cl-user) (defpackage cl-cookie-test (:use :cl :cl-cookie :prove) (:import-from :cl-cookie :parse-cookie-date :match-cookie-path :match-cookie)) (in-package :cl-cookie-test) (plan nil) (subtest "parse-cookie-date" (loop for (date . rfc3339) in '(("Wed, 06-Feb-2008 21:01:38 GMT" . "2008-02-06T21:01:38+0000") ("Wed, 06-Feb-08 21:01:38 GMT" . "2008-02-06T21:01:38+0000") ("Tue Feb 13 08:00:00 2007 GMT" . "2007-02-13T08:00:00+0000") ("Wednesday, 07-February-2027 08:55:23 GMT" . "2027-02-07T08:55:23+0000") ("Wed, 07-02-2017 10:34:45 GMT" . "2017-02-07T10:34:45+0000")) do (let ((parsed (parse-cookie-date date))) (ok parsed (format nil "Can parse ~S" date)) (is (local-time:universal-to-timestamp parsed) (local-time:parse-timestring rfc3339) :test #'local-time:timestamp=)))) (subtest "parse-set-cookie-header" (is (parse-set-cookie-header "SID=31d4d96e407aad42" "example.com" "/") (make-cookie :name "SID" :value "31d4d96e407aad42" :origin-host "example.com" :path "/") :test #'cookie= "name and value") (is (parse-set-cookie-header "SID=" "example.com" "/") (make-cookie :name "SID" :value "" :origin-host "example.com" :path "/") :test #'cookie= "no value") (is (parse-set-cookie-header "SID=31d4d96e407aad42; Path=/; Domain=example.com" "example.com" "/") (make-cookie :name "SID" :value "31d4d96e407aad42" :origin-host "example.com" :path "/" :domain "example.com") :test #'cookie= "path and domain") (is (parse-set-cookie-header "SID=31d4d96e407aad42; Path=/; Secure; HttpOnly" "example.com" "/") (make-cookie :name "SID" :value "31d4d96e407aad42" :origin-host "example.com" :path "/" :secure-p t :httponly-p t) :test #'cookie-equal "secure and httponly")) (subtest "write-cookie-header" (is (write-cookie-header nil) nil) (is (write-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42")) "SID=31d4d96e407aad42") (is (write-cookie-header (list (make-cookie :name "SID" :value "31d4d96e407aad42") (make-cookie :name "lang" :value "en-US"))) "SID=31d4d96e407aad42; lang=en-US")) (subtest "match-cookie-path" (ok (match-cookie-path "/" "/")) (ok (match-cookie-path "/" "")) (ok (match-cookie-path "" "/")) (ok (not (match-cookie-path "/" "/accounts"))) (ok (match-cookie-path "/accounts" "/")) (ok (match-cookie-path "/accounts/nitro_idiot" "/")) (ok (not (match-cookie-path "/" "/accounts"))) (ok (match-cookie-path "/accounts" "/accounts")) (ok (match-cookie-path "/accounts/" "/accounts")) (ok (not (match-cookie-path "/accounts-page" "/accounts"))) (ok (match-cookie-path "/accounts/nitro_idiot" "/accounts"))) (subtest "match-cookie" (subtest "cookie with domain and path" (let ((cookie (make-cookie :name "LSID" :value "DQAAAK...Eaem_vYg" :origin-host "docs.foo.com" :domain ".foo.com" :path "/accounts"))) (diag "path") (ok (not (match-cookie cookie "docs.foo.com" "/"))) (ok (match-cookie cookie "docs.foo.com" "/accounts")) (ok (match-cookie cookie "docs.foo.com" "/accounts/")) (ok (match-cookie cookie "docs.foo.com" "/accounts/nitro_idiot")) (ok (not (match-cookie cookie "docs.foo.com" "/accounts-page" :securep t))) (diag "domain") (ok (not (match-cookie cookie "foo.com" "/" :securep t)) "Send only to the origin-host when :host is NIL") (ok (not (match-cookie cookie "one.docs.foo.com" "/" :securep t)) "Send only to the origin-host when :host is NIL"))) (subtest "cookie with path" (let ((cookie (make-cookie :name "LSID" :value "DQAAAK...Eaem_vYg" :origin-host "docs.foo.com" :path "/accounts" :secure-p t :httponly-p t))) (diag "secure") (ok (not (match-cookie cookie "docs.foo.com" "/accounts"))) (ok (match-cookie cookie "docs.foo.com" "/accounts" :securep t)) (diag "path") (ok (not (match-cookie cookie "docs.foo.com" "/" :securep t))) (ok (match-cookie cookie "docs.foo.com" "/accounts" :securep t)) (ok (match-cookie cookie "docs.foo.com" "/accounts/" :securep t)) (ok (match-cookie cookie "docs.foo.com" "/accounts/nitro_idiot" :securep t)) (ok (not (match-cookie cookie "docs.foo.com" "/accounts-page" :securep t))) (diag "domain") (ok (not (match-cookie cookie "foo.com" "/" :securep t)) "Send only to the origin-host when :host is NIL") (ok (not (match-cookie cookie "one.docs.foo.com" "/" :securep t)) "Send only to the origin-host when :host is NIL")))) (subtest "cookie-jar" (let ((cookie-jar (make-cookie-jar))) (is (length (cookie-jar-cookies cookie-jar)) 0 "initial cookie jar is empty") (merge-cookies cookie-jar (list (make-cookie :name "SID" :value "31d4d96e407aad42" :domain "example.com" :path "/") (make-cookie :name "lang" :value "en-US" :domain "example.com" :path "/accounts"))) (is (length (cookie-jar-cookies cookie-jar)) 2) (merge-cookies cookie-jar (list (make-cookie :name "id" :value "30" :domain "example.com"))) (is (length (cookie-jar-cookies cookie-jar)) 3) (merge-cookies cookie-jar (list (make-cookie :name "lang" :value "ja-JP" :domain "example.com" :path "/accounts"))) (subtest "can overwrite" (is (length (cookie-jar-cookies cookie-jar)) 3) (is (cookie-value (find "lang" (cookie-jar-cookies cookie-jar) :key #'cookie-name :test #'string=)) "ja-JP")) (subtest "not overwrite other domain cookies" (merge-cookies cookie-jar (list (make-cookie :name "lang" :value "fr-FR" :domain "www.example.com"))) (is (length (cookie-jar-cookies cookie-jar)) 4)) (subtest "Cross site cooking" (merge-cookies cookie-jar (list (make-cookie :name "name" :value "Ultraman" :domain ".com"))) (is (cookie-jar-host-cookies cookie-jar "hatena.com" "/") nil)))) (subtest "write-set-cookie-header" (is (write-set-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42")) "SID=31d4d96e407aad42" :test #'string= "name and value") (is (write-set-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42" :domain "www.example.com")) "SID=31d4d96e407aad42; Domain=www.example.com" :test #'string= "name, value, and domain") (is (write-set-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42" :domain "www.example.com" :path "/users")) "SID=31d4d96e407aad42; Path=/users; Domain=www.example.com" :test #'string= "name, value, domain, and path") (is (write-set-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42" :expires (encode-universal-time 6 22 19 25 1 2002))) "SID=31d4d96e407aad42; Expires=Sat, 26 Jan 2002 00:22:06 GMT" :test #'string= "name, value, and expires") (is (write-set-cookie-header (make-cookie :name "SID" :value "31d4d96e407aad42" :expires (encode-universal-time 6 22 19 25 1 2002) :secure-p t :httponly-p t)) "SID=31d4d96e407aad42; Expires=Sat, 26 Jan 2002 00:22:06 GMT; Secure; HttpOnly" :test #'string=)) (finalize)
7,607
Common Lisp
.lisp
141
45.390071
134
0.606309
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
f0671d6fa496a501d42734ce49e9ef83980709b8fed39428a5cb5ae90c93c5e5
42,861
[ -1 ]
42,862
arc.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/arc.lisp
;;; Copyright (c) 2008 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; arc.lisp (in-package #:vecto) ;;; Adapted from Ben Deane's com.elbeno.curve 0.1 library, with ;;; permission. See http://www.elbeno.com/lisp/ for the original. (defparameter +cubic-error-coeffs-0+ (make-array '(2 4 4) :initial-contents '((( 3.85268 -21.229 -0.330434 0.0127842) (-1.61486 0.706564 0.225945 0.263682) (-0.910164 0.388383 0.00551445 0.00671814) (-0.630184 0.192402 0.0098871 0.0102527)) ((-0.162211 9.94329 0.13723 0.0124084) (-0.253135 0.00187735 0.0230286 0.01264) (-0.0695069 -0.0437594 0.0120636 0.0163087) (-0.0328856 -0.00926032 -0.00173573 0.00527385))))) (defparameter +cubic-error-coeffs-1+ (make-array '(2 4 4) :initial-contents '((( 0.0899116 -19.2349 -4.11711 0.183362) ( 0.138148 -1.45804 1.32044 1.38474) ( 0.230903 -0.450262 0.219963 0.414038) ( 0.0590565 -0.101062 0.0430592 0.0204699)) (( 0.0164649 9.89394 0.0919496 0.00760802) ( 0.0191603 -0.0322058 0.0134667 -0.0825018) ( 0.0156192 -0.017535 0.00326508 -0.228157) (-0.0236752 0.0405821 -0.0173086 0.176187))))) ;;; [elbeno:] ;;; compute the error of a cubic bezier ;;; that approximates an elliptical arc ;;; with radii a, b ;;; between angles eta1 and eta2 (defun calc-c-term (i b/a etasum arr) (loop for j from 0 to 3 sum (* (/ (+ (* (aref arr i j 0) b/a b/a) (* (aref arr i j 1) b/a) (aref arr i j 2)) (+ (aref arr i j 3) b/a)) (cos (* j etasum))))) (defun bezier-error (a b eta1 eta2) (let* ((b/a (/ b a)) (etadiff (- eta2 eta1)) (etasum (+ eta2 eta1)) (arr (if (< b/a 0.25) +cubic-error-coeffs-0+ +cubic-error-coeffs-1+))) (* (/ (+ (* 0.001 b/a b/a) (* 4.98 b/a) 0.207) (+ b/a 0.0067)) a (exp (+ (calc-c-term 0 b/a etasum arr) (* (calc-c-term 1 b/a etasum arr) etadiff)))))) (defun ellipse-val (cx cy a b theta eta) (values (+ cx (* a (cos theta) (cos eta)) (* (- b) (sin theta) (sin eta))) (+ cy (* a (sin theta) (cos eta)) (* b (cos theta) (sin eta))))) (defun ellipse-deriv-val (a b theta eta) (values (+ (* (- a) (cos theta) (sin eta)) (* (- b) (sin theta) (cos eta))) (+ (* (- a) (sin theta) (sin eta)) (* b (cos theta) (cos eta))))) ;;; FIXME: The original elbeno code used real abstraction to manage ;;; points and curves and splines. I ripped it out and replaced it ;;; with the following ugly mess. Fix, fix, fix. For example, it might ;;; be possible to use cl-vectors to accumulate the path instead of ;;; using lists of conses. (defun approximate-arc-single (cx cy a b theta eta1 eta2) (let* ((etadiff (- eta2 eta1)) (k (tan (/ etadiff 2))) (alpha (* (sin etadiff) (/ (1- (sqrt (+ 4 (* 3 k k)))) 3))) px1 py1 px2 py2 qx1 qy1 qx2 qy2 sx1 sy1 sx2 sy2) (setf (values px1 py1) (ellipse-val cx cy a b theta eta1) (values px2 py2) (ellipse-val cx cy a b theta eta2) (values sx1 sy1) (ellipse-deriv-val a b theta eta1) (values sx2 sy2) (ellipse-deriv-val a b theta eta2) qx1 (+ px1 (* alpha sx1)) qy1 (+ py1 (* alpha sy1)) qx2 (- px2 (* alpha sx2)) qy2 (- py2 (* alpha sy2))) (list (cons px1 py1) (cons qx1 qy1) (cons qx2 qy2) (cons px2 py2)))) (defun approximate-arc (cx cy a b theta eta1 eta2 err) (cond ((< eta2 eta1) (error "approximate-arc: eta2 must be bigger than eta1")) ((> eta2 (+ eta1 (/ pi 2) (* eta2 long-float-epsilon))) (let ((etamid (+ eta1 (/ pi 2) (* eta2 long-float-epsilon)))) (nconc (approximate-arc cx cy a b theta eta1 etamid err) (approximate-arc cx cy a b theta etamid eta2 err)))) (t (if (> err (bezier-error a b eta1 eta2)) (list (approximate-arc-single cx cy a b theta eta1 eta2)) (let ((etamid (/ (+ eta1 eta2) 2))) (nconc (approximate-arc cx cy a b theta eta1 etamid err) (approximate-arc cx cy a b theta etamid eta2 err))))))) (defun approximate-elliptical-arc (cx cy a b theta eta1 eta2 &optional (err 0.5)) "Approximate an elliptical arc with a cubic bezier spline." (if (> b a) (approximate-arc cx cy b a (+ theta (/ pi 2)) (- eta1 (/ pi 2)) (- eta2 (/ pi 2)) err) (approximate-arc cx cy a b theta eta1 eta2 err)))
6,288
Common Lisp
.lisp
140
36.814286
73
0.57222
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
ff672eda383839bd9a6e91be35f292eddfdec51eb40d5066f85560b8ced7460e
42,862
[ 67513 ]
42,863
clipping-paths.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/clipping-paths.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: clipping-paths.lisp,v 1.2 2007/10/01 16:25:48 xach Exp $ (in-package #:vecto) ;;; Clipping paths are represented as a grayscale channel against ;;; which drawing operations are masked; it's intersected with the ;;; alpha channel. They are part of the graphics state that are saved ;;; and restored by WITH-GRAPHICS-STATE. However, there's no reason to ;;; pay a channel copying penalty if the clipping path is not ;;; modified, or pay a data creation/drawing penalty if the clipping ;;; path is empty. ;;; ;;; This is implemented by making WRITABLE-CLIPPING-DATA the method to ;;; obtain the data of a clipping path; it will create data for an ;;; empty clipping path, and copy data for a clipping path in a ;;; temporary graphics state. If WRITABLE-CLIPPING-DATA is never ;;; called, no mask will be created, and drawing operations won't ;;; bother consulting the clipping path. ;;; ;;; TODO: Store a bounding box with a clipping path, so drawing can be ;;; limited to the clipping path area when possible. (defclass clipping-path () ((height :initarg :height :accessor height) (width :initarg :width :accessor width) (data :initarg :data :accessor data) (scratch :initarg :scratch :accessor scratch :documentation "A temporary channel used to store the new clipping path to intersect with the old one."))) (defclass empty-clipping-path (clipping-path) ()) (defclass proxy-clipping-path (clipping-path) ()) (defmethod print-object ((clipping-path clipping-path) stream) (print-unreadable-object (clipping-path stream :type t :identity t) (format stream "~Dx~D" (width clipping-path) (height clipping-path)))) (defmethod copy ((clipping-path clipping-path)) (make-instance 'proxy-clipping-path :data (data clipping-path) :scratch (scratch clipping-path) :height (height clipping-path) :width (width clipping-path))) (defmethod copy ((clipping-path empty-clipping-path)) (make-instance 'empty-clipping-path :height (height clipping-path) :width (width clipping-path))) (defgeneric emptyp (object) (:method (object) nil) (:method ((object empty-clipping-path)) t)) (defun make-clipping-channel (width height initial-element) (make-array (* width height) :element-type '(unsigned-byte 8) :initial-element initial-element)) (defgeneric clipping-data (object) (:method ((clipping-path clipping-path)) (data clipping-path)) (:method ((clipping-path empty-clipping-path)) nil)) (defgeneric writable-clipping-data (object) (:method ((clipping-path clipping-path)) (data clipping-path)) (:method ((clipping-path empty-clipping-path)) (let* ((width (width clipping-path)) (height (height clipping-path)) (data (make-clipping-channel width height #xFF)) (scratch (make-clipping-channel width height #x00))) (change-class clipping-path 'clipping-path :data data :scratch scratch) data)) (:method ((clipping-path proxy-clipping-path)) (let ((data (copy-seq (data clipping-path)))) (change-class clipping-path 'clipping-path :data data) data))) (defun make-clipping-path (width height) (make-instance 'empty-clipping-path :width width :height height))
4,752
Common Lisp
.lisp
107
40.168224
74
0.710492
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
89143809ad6fb688c27d9e26d1cc5f475245bbc3fda5bc19dee3c64be367071e
42,863
[ 336995 ]
42,864
package.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/package.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: package.lisp,v 1.17 2007/10/01 14:13:11 xach Exp $ (cl:defpackage #:vecto (:use #:cl) (:import-from #:zpb-ttf #:open-font-loader #:xmin #:xmax #:ymin #:ymax #:bounding-box) (:export ;; canvas operations #:with-canvas #:clear-canvas #:save-png #:save-png-stream ;; path construction #:move-to #:line-to #:curve-to #:quadratic-to #:close-subpath #:stroke-to-paths #:arc #:arcn #:ellipse-arc #:ellipse-arcn ;; Clipping #:end-path-no-op #:clip-path #:even-odd-clip-path ;; path construction one-offs #:rectangle #:rounded-rectangle #:centered-ellipse-path #:centered-circle-path #:+kappa+ ;; painting #:fill-path #:even-odd-fill #:stroke #:fill-and-stroke #:even-odd-fill-and-stroke ;; graphics state #:with-graphics-state #:set-line-cap #:set-line-join #:set-line-width #:set-dash-pattern #:set-rgba-stroke #:set-rgb-stroke #:set-rgba-fill #:set-rgb-fill #:set-gradient-fill #:linear-domain #:bilinear-domain #:cartesian-coordinates #:polar-coordinates ;; graphics state coordinate transforms #:translate #:rotate #:rotate-degrees #:skew #:scale ;; text #:*default-character-spacing* #:get-font #:set-font #:set-character-spacing #:draw-string #:string-paths #:draw-centered-string #:centered-string-paths #:string-bounding-box))
2,886
Common Lisp
.lisp
100
24.94
70
0.678276
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
b8ce552f9d6073dfe99a51308e512d13a443c1976f4c47fd88cd36aaf913b3e8
42,864
[ -1 ]
42,865
utils.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/utils.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: utils.lisp,v 1.3 2007/09/20 17:41:21 xach Exp $ (in-package #:vecto) (defun clamp-range (low value high) (min (max value low) high)) (defun float-octet (float) "Convert a float in the range 0.0 - 1.0 to an octet." (values (round (* float 255.0)))) (defun octet-float (octet) "Convert an octet to a float." (/ octet 255.0)) ;; hyperdoc definitions (defvar *hyperdoc-base-uri* "http://www.xach.com/lisp/vecto/") (let ((exported-symbols-alist (loop for symbol being the external-symbols of :vecto collect (cons symbol (concatenate 'string "#" (string-downcase symbol)))))) (defun hyperdoc-lookup (symbol type) (declare (ignore type)) (cdr (assoc symbol exported-symbols-alist :test #'eq))))
2,228
Common Lisp
.lisp
49
40.938776
70
0.688909
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e5d069e5293a346432a4cd9a69421e3f8d86c1e60b1ecf3ad18ce566e96c418e
42,865
[ 88842 ]
42,866
user-drawing.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/user-drawing.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: user-drawing.lisp,v 1.21 2007/10/01 14:12:55 xach Exp $ (in-package #:vecto) (defvar *graphics-state*) (setf (documentation '*graphics-state* 'variable) "The currently active graphics state. Bound for the duration of WITH-GRAPICS-STATE.") ;;; Low-level path construction (defun %move-to (state x y) (let ((path (paths:create-path :open-polyline))) (push (setf (path state) path) (paths state)) (paths:path-reset path (paths:make-point x y)))) (defun %line-to (state x y) (paths:path-extend (path state) (paths:make-straight-line) (paths:make-point x y))) (defun %curve-to (state cx1 cy1 cx2 cy2 x y) "Draw a cubic Bezier curve from the current point to (x,y) through two control points." (let ((control-point-1 (paths:make-point cx1 cy1)) (control-point-2 (paths:make-point cx2 cy2)) (end-point (paths:make-point x y))) (paths:path-extend (path state) (paths:make-bezier-curve (list control-point-1 control-point-2)) end-point))) (defun %quadratic-to (state cx cy x y) "Draw a quadratic Bezier curve from the current point to (x,y) through one control point." (paths:path-extend (path state) (paths:make-bezier-curve (list (paths:make-point cx cy))) (paths:make-point x y))) (defun draw-arc-curves (curves) (destructuring-bind (((startx . starty) &rest ignored-curve) &rest ignored-curves) curves (declare (ignore ignored-curve ignored-curves)) (if (path *graphics-state*) (line-to startx starty) (move-to startx starty))) (loop for ((x1 . y1) (cx1 . cy1) (cx2 . cy2) (x2 . y2)) in curves do (curve-to cx1 cy1 cx2 cy2 x2 y2))) (defun %close-subpath (state) (setf (paths::path-type (path state)) :closed-polyline)) ;;; Clipping path (defun %end-path-no-op (state) (after-painting state)) (defun %clip-path (state) (call-after-painting state (make-clipping-path-function state :nonzero-winding))) (defun %even-odd-clip-path (state) (call-after-painting state (make-clipping-path-function state :even-odd))) ;;; Text (defun %get-font (state file) (find-font-loader state file)) (defun %set-font (state loader size) (let* ((scale (loader-font-scale size loader)) (matrix (scaling-matrix scale scale))) (setf (font state) (make-instance 'font :loader loader :transform-matrix matrix :size size)))) (defun %string-paths (state x y string) (let ((font (font state))) (unless font (error "No font currently set")) (string-primitive-paths x y string font :character-spacing (character-spacing state)))) (defun %draw-string (state x y string) (draw-paths/state (%string-paths state x y string) state)) (defun %draw-centered-string (state x y string) (let* ((font (font state)) (bbox (string-bounding-box string (size font) (loader font) :character-spacing (character-spacing state))) (xmin (xmin bbox)) (width/2 (/ (- (xmax bbox) xmin) 2.0))) (%draw-string state (- x (+ width/2 xmin)) y string))) (defun string-paths (x y string) (setf (paths *graphics-state*) (append (paths *graphics-state*) (%string-paths *graphics-state* x y string))) (values)) (defun centered-string-paths (x y string) (let* ((font (font *graphics-state*)) (bbox (string-bounding-box string (size font) (loader font))) (width/2 (/ (- (xmax bbox) (xmin bbox)) 2.0))) (setf (paths *graphics-state*) (append (paths *graphics-state*) (%string-paths *graphics-state* (- x width/2) y string))) (values))) ;;; Low-level transforms (defun %translate (state tx ty) (apply-matrix state (translation-matrix tx ty))) (defun %scale (state sx sy) (apply-matrix state (scaling-matrix sx sy))) (defun %skew (state x y) (apply-matrix state (skewing-matrix x y))) (defun %rotate (state radians) (apply-matrix state (rotation-matrix radians))) ;;; User-level commands (defun move-to (x y) (%move-to *graphics-state* x y)) (defun line-to (x y) (%line-to *graphics-state* x y)) (defun curve-to (cx1 cy1 cx2 cy2 x y) (%curve-to *graphics-state* cx1 cy1 cx2 cy2 x y)) (defun quadratic-to (cx cy x y) (%quadratic-to *graphics-state* cx cy x y)) (defun arc (cx cy r theta1 theta2) (loop while (< theta2 theta1) do (incf theta2 (* 2 pi))) (let ((curves (approximate-elliptical-arc cx cy r r 0 theta1 theta2))) (draw-arc-curves curves))) (defun arcn (cx cy r theta1 theta2) (loop while (< theta1 theta2) do (decf theta2 (* 2 pi))) (let ((curves (approximate-elliptical-arc cx cy r r 0 theta2 theta1))) (draw-arc-curves (nreverse (mapcar #'nreverse curves))))) (defun ellipse-arc (cx cy rx ry theta eta1 eta2) (loop while (< eta2 eta1) do (incf eta2 (* 2 pi))) (let ((curves (approximate-elliptical-arc cx cy rx ry theta eta1 eta2))) (draw-arc-curves curves))) (defun ellipse-arcn (cx cy rx ry theta eta1 eta2) (loop while (< eta1 eta2) do (decf eta2 (* 2 pi))) (let ((curves (approximate-elliptical-arc cx cy rx ry theta eta2 eta1))) (draw-arc-curves (nreverse (mapcar #'nreverse curves))))) (defun close-subpath () (%close-subpath *graphics-state*)) (defun end-path-no-op () (%end-path-no-op *graphics-state*) (clear-paths *graphics-state*)) (defun clip-path () (%clip-path *graphics-state*)) (defun even-odd-clip-path () (%even-odd-clip-path *graphics-state*)) (defun get-font (file) (%get-font *graphics-state* file)) (defun set-font (font size) (%set-font *graphics-state* font size)) (defun set-character-spacing (spacing) (setf (character-spacing *graphics-state*) spacing)) (defun draw-string (x y string) (%draw-string *graphics-state* x y string)) (defun draw-centered-string (x y string) (%draw-centered-string *graphics-state* x y string)) (defun set-dash-pattern (vector phase) (if (zerop (length vector)) (setf (dash-vector *graphics-state*) nil (dash-phase *graphics-state*) nil) (setf (dash-vector *graphics-state*) vector (dash-phase *graphics-state*) phase))) (defun set-line-cap (style) (assert (member style '(:butt :square :round))) (setf (cap-style *graphics-state*) style)) (defun set-line-join (style) (assert (member style '(:bevel :miter :round))) (setf (join-style *graphics-state*) (if (eql style :bevel) :none style))) (defun set-line-width (width) (setf (line-width *graphics-state*) width)) (defun set-rgba-color (color r g b a) (setf (red color) (clamp-range 0.0 r 1.0) (green color) (clamp-range 0.0 g 1.0) (blue color) (clamp-range 0.0 b 1.0) (alpha color) (clamp-range 0.0 a 1.0)) color) (defun set-rgb-color (color r g b) (setf (red color) (clamp-range 0.0 r 1.0) (green color) (clamp-range 0.0 g 1.0) (blue color) (clamp-range 0.0 b 1.0) (alpha color) 1.0) color) (defun set-rgb-stroke (r g b) (set-rgb-color (stroke-color *graphics-state*) r g b)) (defun set-rgba-stroke (r g b a) (set-rgba-color (stroke-color *graphics-state*) r g b a)) (defun set-rgb-fill (r g b) (clear-fill-source *graphics-state*) (set-rgb-color (fill-color *graphics-state*) r g b)) (defun set-rgba-fill (r g b a) (clear-fill-source *graphics-state*) (set-rgba-color (fill-color *graphics-state*) r g b a)) (defun stroke () (draw-stroked-paths *graphics-state*) (clear-paths *graphics-state*)) (defun stroke-to-paths () (let ((paths (state-stroke-paths *graphics-state*))) (clear-paths *graphics-state*) (setf (paths *graphics-state*) paths) (%close-subpath *graphics-state*))) (defun fill-path () (draw-filled-paths *graphics-state*) (after-painting *graphics-state*) (clear-paths *graphics-state*)) (defun even-odd-fill () (draw-even-odd-filled-paths *graphics-state*) (after-painting *graphics-state*) (clear-paths *graphics-state*)) (defun fill-and-stroke () (draw-filled-paths *graphics-state*) (draw-stroked-paths *graphics-state*) (after-painting *graphics-state*) (clear-paths *graphics-state*)) (defun even-odd-fill-and-stroke () (draw-even-odd-filled-paths *graphics-state*) (draw-stroked-paths *graphics-state*) (after-painting *graphics-state*) (clear-paths *graphics-state*)) (defun clear-canvas () (let ((color (fill-color *graphics-state*))) (fill-image (image-data *graphics-state*) (red color) (green color) (blue color) (alpha color)))) (defun translate (x y) (%translate *graphics-state* x y)) (defun scale (x y) (%scale *graphics-state* x y)) (defun skew (x y) (%skew *graphics-state* x y)) (defun rotate (radians) (%rotate *graphics-state* radians)) (defun rotate-degrees (degrees) (%rotate *graphics-state* (* (/ pi 180) degrees))) (defun save-png (file) (zpng:write-png (image *graphics-state*) file)) (defun save-png-stream (stream) (zpng:write-png-stream (image *graphics-state*) stream)) (defmacro with-canvas ((&key width height) &body body) `(let ((*graphics-state* (make-instance 'graphics-state))) (state-image *graphics-state* ,width ,height) (unwind-protect (progn ,@body) (clear-state *graphics-state*)))) (defmacro with-graphics-state (&body body) `(let ((*graphics-state* (copy *graphics-state*))) ,@body))
11,165
Common Lisp
.lisp
270
35.877778
78
0.653388
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5615b213227cf603dcb84e48ba8d0c4c70525c785aa24eae24879408d3670b10
42,866
[ 118613 ]
42,867
color.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/color.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: color.lisp,v 1.3 2007/09/20 17:42:03 xach Exp $ (in-package #:vecto) (defclass color () ()) (defclass rgba-color (color) ((red :initarg :red :accessor red) (green :initarg :green :accessor green) (blue :initarg :blue :accessor blue) (alpha :initarg :alpha :accessor alpha)) (:default-initargs :red 0.0 :green 0.0 :blue 0.0 :alpha 1.0)) (defmethod copy ((color rgba-color)) (make-instance 'rgba-color :red (red color) :green (green color) :blue (blue color) :alpha (alpha color)))
1,969
Common Lisp
.lisp
50
35.94
70
0.701828
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
79e087263901180e8545dd50f62a5220bd3551a0b548ae07b01e6546547f0e3f
42,867
[ 412823 ]
42,868
drawing.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/drawing.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: drawing.lisp,v 1.17 2007/10/01 19:05:13 xach Exp $ (in-package #:vecto) (deftype octet () '(unsigned-byte 8)) (deftype vector-index () `(mod ,array-dimension-limit)) (deftype octet-vector () '(simple-array (unsigned-byte 8) (*))) (defun nonzero-winding-alpha (alpha) (min 255 (abs alpha))) (defun even-odd-alpha (alpha) (let ((value (mod alpha 512))) (min 255 (if (< value 256) value (- 512 value))))) ;; ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) ) (defun imult (a b) (let ((temp (+ (* a b) #x80))) (logand #xFF (ash (+ (ash temp -8) temp) -8)))) (defun lerp (p q a) (logand #xFF (+ p (imult a (- q p))))) (defun prelerp (p q a) (logand #xFF (- (+ p q) (imult a p)))) (defun blend-function-blend (fg a.fg bg a.bg) (lerp (imult bg a.bg) fg a.fg)) (defun blend-function-add (fg a.fg bg a.bg) (clamp-range 0 (+ (imult fg a.fg) (imult bg a.bg)) 255)) (defun draw-function (data width height fill-source alpha-fun blend-fun) "From http://www.teamten.com/lawrence/graphics/premultiplication/" (declare (ignore height)) (lambda (x y alpha) (multiple-value-bind (r.fg g.fg b.fg a.fg) (funcall fill-source x y) (setf alpha (funcall alpha-fun alpha)) (when (plusp alpha) (let* ((i (* +png-channels+ (+ x (* y width)))) (r.bg (aref data (+ i 0))) (g.bg (aref data (+ i 1))) (b.bg (aref data (+ i 2))) (a.bg (aref data (+ i 3))) (a.fg (imult alpha a.fg)) (gamma (prelerp a.fg a.bg a.bg))) (flet ((blend (fg bg) (let ((value (funcall blend-fun fg a.fg bg a.bg))) (float-octet (/ value gamma))))) (unless (zerop gamma) (setf (aref data (+ i 0)) (blend r.fg r.bg) (aref data (+ i 1)) (blend g.fg g.bg) (aref data (+ i 2)) (blend b.fg b.bg))) (setf (aref data (+ i 3)) gamma))))))) (defun draw-function/clipped (data clip-data width height fill-source alpha-fun blend-fun) "Like DRAW-FUNCTION, but uses uses the clipping channel." (declare (ignore height)) (lambda (x y alpha) (let* ((clip-index (+ x (* y width))) (clip (aref clip-data clip-index))) (setf alpha (imult clip (funcall alpha-fun alpha))) (when (plusp alpha) (multiple-value-bind (r.fg g.fg b.fg a.fg) (funcall fill-source x y) (let* ((i (* clip-index +png-channels+)) (r.bg (aref data (+ i 0))) (g.bg (aref data (+ i 1))) (b.bg (aref data (+ i 2))) (a.bg (aref data (+ i 3))) (a.fg (imult alpha a.fg)) (gamma (prelerp a.fg a.bg a.bg))) (flet ((blend (fg bg) (let ((value (funcall blend-fun fg a.fg bg a.bg))) (float-octet (/ value gamma))))) (unless (zerop gamma) (setf (aref data (+ i 0)) (blend r.fg r.bg) (aref data (+ i 1)) (blend g.fg g.bg) (aref data (+ i 2)) (blend b.fg b.bg))) (setf (aref data (+ i 3)) gamma)))))))) (defun make-draw-function (data clipping-path width height fill-source alpha-fun blend-fun) (if (emptyp clipping-path) (draw-function data width height fill-source alpha-fun blend-fun) (draw-function/clipped data (clipping-data clipping-path) width height fill-source alpha-fun blend-fun))) (defun intersect-clipping-paths (data temp) (declare (type (simple-array (unsigned-byte 8) (*)) data temp)) (map-into data #'imult temp data)) (defun draw-clipping-path-function (data width height alpha-fun) (declare (ignore height) (type (simple-array (unsigned-byte 8) (*)) data)) (lambda (x y alpha) (let ((i (+ x (* width y)))) (let ((alpha (funcall alpha-fun alpha))) (setf (aref data i) alpha))))) (defun draw-paths (&key width height paths transform-function draw-function) "Use DRAW-FUNCTION as a callback for the cells sweep function for the set of paths PATHS." (let ((state (aa:make-state)) (paths (mapcar (lambda (path) ;; FIXME: previous versions lacked ;; paths:path-clone, and this broke fill & ;; stroke because transform-path damages the ;; paths. It would be nicer if transform-path ;; wasn't destructive, since I didn't expect ;; it to be. (transform-path (paths:path-clone path) transform-function)) paths))) (vectors:update-state state paths) (aa:cells-sweep/rectangle state 0 0 width height draw-function))) ;;; FIXME: this was added for drawing text paths, but the text ;;; rendering mode could be changed in the future, making it a little ;;; silly to have a fixed draw-function. (defun draw-paths/state (paths state) (draw-paths :paths paths :width (width state) :height (height state) :transform-function (transform-function state) :draw-function (fill-draw-function state))) (defun fill-image (image-data red green blue alpha) "Completely fill IMAGE with the given colors." (let ((r (float-octet red)) (g (float-octet green)) (b (float-octet blue)) (a (float-octet alpha))) (do ((h 0 (+ h 4)) (i 1 (+ i 4)) (j 2 (+ j 4)) (k 3 (+ k 4))) ((<= (length image-data) k)) (setf (aref image-data h) r (aref image-data i) g (aref image-data j) b (aref image-data k) a)))) (defun color-source-function (color) (let ((red (float-octet (red color))) (green (float-octet (green color))) (blue (float-octet (blue color))) (alpha (float-octet (alpha color)))) (lambda (x y) (declare (ignore x y)) (values red green blue alpha)))) (defun fill-source-function (state) (or (fill-source state) (color-source-function (fill-color state)))) (defun stroke-source-function (state) (color-source-function (stroke-color state))) (defun state-draw-function (state fill-source fill-style) "Create a draw function for the graphics state STATE." (make-draw-function (image-data state) (clipping-path state) (width state) (height state) fill-source (ecase fill-style (:even-odd #'even-odd-alpha) (:nonzero-winding #'nonzero-winding-alpha)) (ecase (blend-style state) (:blend #'blend-function-blend) (:add #'blend-function-add)))) (defun stroke-draw-function (state) (state-draw-function state (stroke-source-function state) :nonzero-winding)) (defun fill-draw-function (state) (state-draw-function state (fill-source-function state) :nonzero-winding)) (defun even-odd-fill-draw-function (state) (state-draw-function state (fill-source-function state) :even-odd)) (defun tolerance-scale (state) (let ((matrix (transform-matrix state))) (abs (/ 1.0 (min (transform-matrix-x-scale matrix) (transform-matrix-y-scale matrix)))))) (defun state-stroke-paths (state) "Compute the outline paths of the strokes for the current paths of STATE." (let ((paths (dash-paths (paths state) (dash-vector state) (dash-phase state))) (paths:*bezier-distance-tolerance* (* paths:*bezier-distance-tolerance* (tolerance-scale state)))) (stroke-paths paths :line-width (line-width state) :join-style (join-style state) :cap-style (cap-style state)))) (defun draw-stroked-paths (state) "Create a set of paths representing a stroking of the current paths of STATE, and draw them to the image." (draw-paths :paths (state-stroke-paths state) :width (width state) :height (height state) :transform-function (transform-function state) :draw-function (stroke-draw-function state))) (defun close-paths (paths) (dolist (path paths) (setf (paths::path-type path) :closed-polyline))) (defun draw-filled-paths (state) "Fill the paths of STATE into the image." (close-paths (paths state)) (draw-paths :paths (paths state) :width (width state) :height (height state) :transform-function (transform-function state) :draw-function (fill-draw-function state))) (defun draw-even-odd-filled-paths (state) "Fill the paths of STATE into the image." (close-paths (paths state)) (draw-paths :paths (paths state) :width (width state) :height (height state) :transform-function (transform-function state) :draw-function (even-odd-fill-draw-function state))) (defun draw-clipping-path (state alpha-fun) (let ((data (writable-clipping-data (clipping-path state))) (scratch (scratch (clipping-path state))) (width (width state)) (height (height state))) (declare (type octet-vector data scratch)) (fill scratch 0) (draw-paths :paths (paths state) :width (width state) :height (height state) :transform-function (transform-function state) :draw-function (draw-clipping-path-function scratch width height alpha-fun)) (intersect-clipping-paths data scratch))) (defun make-clipping-path-function (state type) (ecase type (:nonzero-winding (lambda () (draw-clipping-path state #'nonzero-winding-alpha))) (:even-odd (lambda () (draw-clipping-path state #'even-odd-alpha)))))
12,090
Common Lisp
.lisp
273
33.648352
76
0.565627
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
f59f290bc59bb2354ab33d16304e5bc01c0bd4132b8e16170a73345364b497d7
42,868
[ 452644 ]
42,869
graphics-state.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/graphics-state.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: graphics-state.lisp,v 1.15 2007/10/01 02:24:44 xach Exp $ (in-package #:vecto) (defconstant +png-channels+ 4) (defconstant +png-color-type+ :truecolor-alpha) (defvar *default-character-spacing* 1.0d0) (defclass graphics-state () ((paths :initarg :paths :accessor paths) (path :initarg :path :accessor path) (height :initarg :height :accessor height) (width :initarg :width :accessor width) (image :initarg :image :accessor image) (stroke-color :initarg :stroke-color :accessor stroke-color) (line-width :initarg :line-width :accessor line-width) (dash-vector :initarg :dash-vector :accessor dash-vector) (dash-phase :initarg :dash-phase :accessor dash-phase) (fill-color :initarg :fill-color :accessor fill-color) (fill-source :initarg :fill-source :accessor fill-source) (join-style :initarg :join-style :accessor join-style) (cap-style :initarg :cap-style :accessor cap-style) (blend-style :initarg :blend-style :accessor blend-style) (transform-matrix :initarg :transform-matrix :accessor transform-matrix) (clipping-path :initarg :clipping-path :accessor clipping-path) (after-paint-fun :initarg :after-paint-fun :accessor after-paint-fun) (font-loaders :initarg :font-loaders :accessor font-loaders) (font :initarg :font :accessor font) (character-spacing :initarg :character-spacing :accessor character-spacing)) (:default-initargs :paths nil :path nil :stroke-color (make-instance 'rgba-color) :line-width 1.0 :dash-vector nil :dash-phase 0 :fill-color (make-instance 'rgba-color) :fill-source nil :join-style :miter :cap-style :butt :blend-style :blend :transform-matrix (scaling-matrix 1.0 -1.0) :after-paint-fun (constantly nil) :font-loaders (make-hash-table :test 'equal) :font nil :character-spacing *default-character-spacing*)) (defgeneric image-data (state) (:method (state) (zpng:image-data (image state)))) (defgeneric transform-function (state) (:documentation "Return a function that takes x, y coordinates and returns them transformed by STATE's current transformation matrix as multiple values.") (:method (state) (make-transform-function (transform-matrix state)))) (defgeneric call-after-painting (state fun) (:documentation "Call FUN after painting, and reset the post-painting fun to a no-op.") (:method (state fun) (setf (after-paint-fun state) (lambda () (funcall fun) (setf (after-paint-fun state) (constantly nil)))))) (defgeneric after-painting (state) (:documentation "Invoke the post-painting function.") (:method (state) (funcall (after-paint-fun state)))) (defgeneric apply-matrix (state matrix) (:documentation "Replace the current transform matrix of STATE with the result of premultiplying it with MATRIX.") (:method (state matrix) (let ((old (transform-matrix state))) (setf (transform-matrix state) (mult matrix old))))) (defgeneric clear-paths (state) (:documentation "Clear out any paths in STATE.") (:method (state) (setf (paths state) nil (path state) nil (after-paint-fun state) (constantly nil)))) (defmethod (setf paths) :after (new-value (state graphics-state)) (setf (path state) (first new-value))) (defun state-image (state width height) "Set the backing image of the graphics state to an image of the specified dimensions." (setf (image state) (make-instance 'zpng:png :width width :height height :color-type +png-color-type+) (width state) width (height state) height (clipping-path state) (make-clipping-path width height)) (apply-matrix state (translation-matrix 0 (- height)))) (defun find-font-loader (state file) (let* ((cache (font-loaders state)) (key (namestring (truename file)))) (or (gethash key cache) (setf (gethash key cache) (zpb-ttf:open-font-loader file))))) (defgeneric close-font-loaders (state) (:documentation "Close any font loaders that were obtained with GET-FONT.") (:method (state) (maphash (lambda (filename loader) (declare (ignore filename)) (ignore-errors (zpb-ttf:close-font-loader loader))) (font-loaders state)))) (defgeneric clear-state (state) (:documentation "Clean up any state in STATE.") (:method ((state graphics-state)) (close-font-loaders state))) (defun clear-fill-source (state) (setf (fill-source state) nil)) (defmethod copy ((state graphics-state)) (make-instance 'graphics-state :paths (paths state) :path (path state) :height (height state) :width (width state) :image (image state) :stroke-color (copy (stroke-color state)) :line-width (line-width state) :dash-vector (copy-seq (dash-vector state)) :dash-phase (dash-phase state) :fill-color (copy (fill-color state)) :fill-source (fill-source state) :join-style (join-style state) :cap-style (cap-style state) :transform-matrix (copy-seq (transform-matrix state)) :clipping-path (copy (clipping-path state)) :after-paint-fun (after-paint-fun state) :font-loaders (font-loaders state) :font (font state) :character-spacing (character-spacing state)))
7,088
Common Lisp
.lisp
195
30.646154
77
0.671857
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
203d8f810cf4445f7fe676c309b96074000f63c9b4e2723440637b5bd1d029bf
42,869
[ -1 ]
42,870
text.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/text.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: text.lisp,v 1.8 2007/09/21 17:39:36 xach Exp $ (in-package #:vecto) (defclass font () ((loader :initarg :loader :accessor loader) (transform-matrix :initarg :transform-matrix :accessor transform-matrix) (size :initarg :size :accessor size))) (defun glyph-path-point (point) (paths:make-point (zpb-ttf:x point) (zpb-ttf:y point))) (defun glyph-paths (glyph) (let* ((paths '()) (path nil)) (zpb-ttf:do-contours (contour glyph (nreverse paths)) (when (plusp (length contour)) (let ((first-point (aref contour 0))) (setf path (paths:create-path :closed-polyline)) (push path paths) (paths:path-reset path (glyph-path-point first-point)) (zpb-ttf:do-contour-segments* (control end) contour (if control (paths:path-extend path (paths:make-bezier-curve (list (glyph-path-point control))) (glyph-path-point end)) (paths:path-extend path (paths:make-straight-line) (glyph-path-point end))))))))) (defun string-glyphs (string loader) "Return STRING converted to a list of ZPB-TTF glyph objects from FONT." (map 'list (lambda (char) (zpb-ttf:find-glyph char loader)) string)) (defun string-primitive-paths (x y string font &key (character-spacing 1.0d0)) "Return the paths of STRING, transformed by the font scale of FONT." (let ((glyphs (string-glyphs string (loader font))) (loader (loader font)) (matrix (mult (transform-matrix font) (translation-matrix x y))) (paths '())) (loop for (glyph . rest) on glyphs do (let ((glyph-paths (glyph-paths glyph)) (fun (make-transform-function matrix))) (dolist (path glyph-paths) (push (transform-path path fun) paths)) (when rest (let* ((next (first rest)) (offset (+ (zpb-ttf:advance-width glyph) (zpb-ttf:kerning-offset glyph next loader)))) (setf matrix (nmult (translation-matrix (* offset character-spacing) 0) matrix)))))) paths)) (defun nmerge-bounding-boxes (b1 b2) "Create a minimal bounding box that covers both B1 and B2 and destructively update B1 with its values. Returns the new box." (setf (xmin b1) (min (xmin b1) (xmin b2)) (ymin b1) (min (ymin b1) (ymin b2)) (xmax b1) (max (xmax b1) (xmax b2)) (ymax b1) (max (ymax b1) (ymax b2))) b1) (defun advance-bounding-box (bbox offset) "Return a bounding box advanced OFFSET units horizontally." (vector (+ (xmin bbox) offset) (ymin bbox) (+ (xmax bbox) offset) (ymax bbox))) (defun empty-bounding-box () (vector most-positive-fixnum most-positive-fixnum most-negative-fixnum most-negative-fixnum)) (defun ntransform-bounding-box (bbox fun) "Return BBOX transformed by FUN; destructively modifies BBOX with the new values." (setf (values (xmin bbox) (ymin bbox)) (funcall fun (xmin bbox) (ymin bbox)) (values (xmax bbox) (ymax bbox)) (funcall fun (xmax bbox) (ymax bbox))) bbox) (defun loader-font-scale (size loader) "Return the horizontal and vertical scaling needed to draw the glyphs of LOADER at SIZE units." (float (/ size (zpb-ttf:units/em loader)))) (defun string-bounding-box (string size loader &key (character-spacing 1.0d0)) (let* ((bbox (empty-bounding-box)) (scale (loader-font-scale size loader)) (fun (make-transform-function (scaling-matrix scale scale))) (glyphs (string-glyphs string loader)) (offset 0)) (loop for (glyph . rest) on glyphs do (let ((glyph-box (advance-bounding-box (bounding-box glyph) (* offset character-spacing)))) (setf bbox (nmerge-bounding-boxes bbox glyph-box)) (incf offset (zpb-ttf:advance-width glyph)) (when rest (let* ((next-glyph (first rest)) (kerning (zpb-ttf:kerning-offset glyph next-glyph loader))) (incf offset kerning))))) (ntransform-bounding-box bbox fun)))
5,836
Common Lisp
.lisp
126
37.690476
80
0.626474
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
28f1e8a4ed661cc1582cf07f614fc6eea0f292bb6273da09a2973e6381dacadd
42,870
[ 481804 ]
42,871
transform-matrix.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/transform-matrix.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: transform-matrix.lisp,v 1.6 2007/09/28 20:35:08 xach Exp $ (in-package #:vecto) (defstruct (transform-matrix (:type vector)) (x-scale 1.0) (y-skew 0.0) (x-skew 0.0) (y-scale 1.0) (x-offset 0.0) (y-offset 0.0)) (defmacro matrix-bind (lambda-list vector &body body) (when (/= (length lambda-list) 6) (error "Bad lambda-list for MATRIX-BIND: 6 arguments required")) (let ((vec (gensym))) `(let ((,vec ,vector)) (let (,@(loop for i from 0 below 6 for var in lambda-list collect (list var `(aref ,vec ,i)))) ,@body)))) (defun matrix (a b c d e f) (vector a b c d e f)) (defun make-transform-function (transform-matrix) (matrix-bind (a b c d e f) transform-matrix (lambda (x y) (values (+ (* a x) (* c y) e) (+ (* b x) (* d y) f))))) (defun transform-coordinates (x y transform-matrix) (matrix-bind (a b c d e f) transform-matrix (values (+ (* a x) (* c y) e) (+ (* b x) (* d y) f)))) ;;; Multiplication: ;;; ;;; a b 0 a*b*0 ;;; c d 0 x c*d*0 ;;; e f 1 e*f*1 (defun mult (m1 m2) (matrix-bind (a b c d e f) m1 (matrix-bind (a* b* c* d* e* f*) m2 (matrix (+ (* a a*) (* b c*)) (+ (* a b*) (* b d*)) (+ (* c a*) (* d c*)) (+ (* c b*) (* d d*)) (+ (* e a*) (* f c*) e*) (+ (* e b*) (* f d*) f*))))) (defun nmult (m1 m2) "Destructive MULT; M2 is modified to hold the result of multiplication." (matrix-bind (a b c d e f) m1 (matrix-bind (a* b* c* d* e* f*) m2 (setf (aref m2 0) (+ (* a a*) (* b c*)) (aref m2 1) (+ (* a b*) (* b d*)) (aref m2 2) (+ (* c a*) (* d c*)) (aref m2 3) (+ (* c b*) (* d d*)) (aref m2 4) (+ (* e a*) (* f c*) e*) (aref m2 5) (+ (* e b*) (* f d*) f*)) m2))) (defun translation-matrix (tx ty) (matrix 1 0 0 1 tx ty)) (defun scaling-matrix (sx sy) (matrix sx 0 0 sy 0 0)) (defun rotation-matrix (theta) (let ((cos (cos theta)) (sin (sin theta))) (matrix cos sin (- sin) cos 0 0))) (defun skewing-matrix (alpha beta) (matrix 1 (tan alpha) (tan beta) 1 0 0)) (defun identity-matrix () (matrix 1.0 0.0 0.0 1.0 0.0 0.0)) ;; From http://www.dr-lex.be/random/matrix_inv.html via Raymond Toy (defun invert-matrix (matrix) (matrix-bind (a11 a12 a21 a22 a31 a32) matrix (let ((a13 0) (a23 0) (a33 1)) (let* ((a33a22 (* a33 a22)) (a32a23 (* a32 a23)) (a33a12 (* a33 a12)) (a32a13 (* a32 a13)) (a23a12 (* a23 a12)) (a22a13 (* a22 a13)) (determinant ;; a11(a33a22-a32a23)-a21(a33a12-a32a13)+a31(a23a12-a22a13) (- (* a11 (- a33a22 a32a23)) (+ (* a21 (- a33a12 a32a13)) (* a31 (- a23a12 a22a13)))))) ;; a33a22-a32a23 -(a33a12-a32a13) ;; -(a33a21-a31a23) a33a11-a31a13 ;; a32a21-a31a22 -(a32a11-a31a12) (let ((a (- a33a22 a32a23)) (b (- (- a33a12 a32a13))) (c (- (- (* a33 a21) (* a31 a23)))) (d (- (* a33 a11) (* a31 a13))) (e (- (* a32 a21) (* a31 a22))) (f (- (- (* a32 a11) (* a31 a12))))) (matrix (/ a determinant) (/ b determinant) (/ c determinant) (/ d determinant) (/ e determinant) (/ f determinant)))))))
5,270
Common Lisp
.lisp
153
26.477124
74
0.514717
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
ac044c3fb74647b2ffeaaf7ab596ee7bbe6185e1e5dec70241284b8e2037515d
42,871
[ 109552 ]
42,872
copy.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/copy.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: copy.lisp,v 1.2 2007/09/20 18:00:37 xach Exp $ (in-package #:vecto) (defgeneric copy (object) (:documentation "Copy an object in a way suitable for pushing to the graphics state stack. That is, if it's an immutable object, simply return the object; otherwise, create a new object with the immutable state copied."))
1,696
Common Lisp
.lisp
34
48.5
70
0.751807
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
66fc398732b09105ef56d2f1cbe4de9bec4f7767b11b0c9a4ee66185c8a8ca51
42,872
[ 93891 ]
42,873
gradient.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/gradient.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; drawing.lisp (in-package #:vecto) (defun linear-domain (param) (clamp-range 0 param 1)) (defun bilinear-domain (param) (let ((param (* 2 (clamp-range 0 param 1)))) (if (<= param 1) param (- 2 param)))) (defun cartesian-coordinates (x0 y0 x1 y1) (lambda (x y) (let ((numerator (+ (* (- x1 x0) (- x x0)) (* (- y1 y0) (- y y0)))) (denominator (+ (expt (- x1 x0) 2) (expt (- y1 y0) 2)))) (/ numerator denominator)))) (defun polar-coordinates (x0 y0 x1 y1) (flet ((distance (start-x start-y end-x end-y) (let ((x-distance (- end-x start-x)) (y-distance (- end-y start-y))) (sqrt (+ (expt x-distance 2) (expt y-distance 2)))))) (let ((original-distance (distance x0 y0 x1 y1))) (lambda (x y) (let ((distance (distance x0 y0 x y))) (- 1 (/ (- original-distance distance) original-distance))))))) (defun set-gradient-fill (x0 y0 r0 g0 b0 a0 x1 y1 r1 g1 b1 a1 &key (extend-start t) (extend-end t) (domain-function 'linear-domain) (coordinates-function 'cartesian-coordinates)) (let* ((matrix (transform-matrix *graphics-state*)) (fun (make-transform-function (invert-matrix matrix))) (gfun (funcall coordinates-function x0 y0 x1 y1))) (setf r0 (float-octet r0) g0 (float-octet g0) b0 (float-octet b0) a0 (float-octet a0) r1 (float-octet r1) g1 (float-octet g1) b1 (float-octet b1) a1 (float-octet a1)) (setf (fill-source *graphics-state*) (lambda (x y) (let ((param (multiple-value-call gfun (funcall fun x y)))) (cond ((and (< param 0) (not extend-start)) (values 0 0 0 0)) ((and (< 1 param) (not extend-end)) (values 0 0 0 0)) (t (setf param (float-octet (funcall domain-function param))) (values (lerp r0 r1 param) (lerp g0 g1 param) (lerp b0 b1 param) (lerp a0 a1 param)))))))))
3,784
Common Lisp
.lisp
85
34.717647
79
0.572434
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
2fd4d3d48d8a4125c22dd40049bba8cbafb4b3e19dec14d62b70f7accbdcb068
42,873
[ 411089 ]
42,874
user-shortcuts.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/user-shortcuts.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: user-shortcuts.lisp,v 1.6 2007/09/21 01:39:07 xach Exp $ (in-package #:vecto) (defconstant +kappa+ (* 4.d0 (/ (- (sqrt 2.0d0) 1.0d0) 3.0d0)) "From http://www.whizkidtech.redprince.net/bezier/circle/, the top Google hit for my vague recollection of this constant.") (defun centered-ellipse-path (x y rx ry) "Add an elliptical subpath centered at X,Y with x radius RX and y radius RY." (let ((cx (* rx +kappa+)) (cy (* ry +kappa+))) ;; upper left (move-to (- x rx) y) (curve-to (- x rx) (+ y cy) (- x cx) (+ y ry) x (+ y ry)) ;; upper right (curve-to (+ x cx) (+ y ry) (+ x rx) (+ y cy) (+ x rx) y) ;; lower right (curve-to (+ x rx) (- y cy) (+ x cx) (- y ry) x (- y ry)) (curve-to (- x cx) (- y ry) (- x rx) (- y cy) (- x rx) y) (close-subpath))) (defun centered-circle-path (x y radius) "Add a circular subpath centered at X,Y with radius RADIUS." (centered-ellipse-path x y radius radius)) (defun rectangle (x y width height) (move-to x y) (line-to (+ x width) y) (line-to (+ x width) (+ y height)) (line-to x (+ y height)) (close-subpath)) (defun rounded-rectangle (x y width height rx ry) ;; FIXME: This should go counter-clockwise, like RECTANGLE! (let* ((x3 (+ x width)) (x2 (- x3 rx)) (x1 (+ x rx)) (x0 x) (xkappa (* rx +kappa+)) (y3 (+ y height)) (y2 (- y3 ry)) (y1 (+ y ry)) (y0 y) (ykappa (* ry +kappa+))) ;; west (move-to x0 y1) (line-to x0 y2) ;; northwest (curve-to x0 (+ y2 ykappa) (- x1 xkappa) y3 x1 y3) ;; north (line-to x2 y3) ;; northeast (curve-to (+ x2 xkappa) y3 x3 (+ y2 ykappa) x3 y2) ;; east (line-to x3 y1) ;; southeast (curve-to x3 (- y1 ykappa) (+ x2 xkappa) y0 x2 y0) ;; south (line-to x1 y0) ;; southwest (curve-to (- x1 xkappa) y0 x0 (+ y0 ykappa) x0 y1) ;; fin (close-subpath)))
3,532
Common Lisp
.lisp
101
29.465347
70
0.599708
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
13e51704e8f0ff8757713818097db9014f916542a1c45a14b4b6a2373b161430
42,874
[ 173274 ]
42,875
paths.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/paths.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: paths.lisp,v 1.2 2007/09/28 18:11:35 xach Exp $ (in-package #:vecto) ;;; Applying a transform function to a path (defgeneric transformablep (interpolation) (:method (interpolation) nil) (:method ((interpolation paths::bezier)) t) (:method ((interpolation (eql :straight-line))) t)) (defun transform-point (point fun) (multiple-value-call #'paths:make-point (funcall fun (paths:point-x point) (paths:point-y point)))) (defgeneric transform-interpolation (interpolation fun) (:method (interpolation fun) (declare (ignore fun)) (error "Unhandled interpolation ~A" interpolation)) (:method ((interpolation symbol) fun) (declare (ignore fun)) interpolation) (:method ((interpolation paths::bezier) fun) (let ((control-points (slot-value interpolation 'paths::control-points))) (dotimes (i (length control-points) interpolation) (setf (aref control-points i) (transform-point (aref control-points i) fun)))))) (defun empty-path-p (path) (zerop (length (paths::path-knots path)))) (defun transform-path (path fun) (when (empty-path-p path) (return-from transform-path path)) (let ((new-path (paths:create-path (paths::path-type path))) (iterator (paths:path-iterator-segmented path (complement #'transformablep)))) (loop (multiple-value-bind (interpolation knot endp) (paths:path-iterator-next iterator) (paths:path-extend new-path (transform-interpolation interpolation fun) (transform-point knot fun)) (when endp (return new-path)))))) (defun transform-paths (paths fun) (mapcar (lambda (path) (transform-path path fun)) paths)) ;;; Applying a dash pattern (defun apply-dash-phase (dash-vector phase) "cl-vectors and PDF have different semantics for dashes. Given a PDF-style dash vector and phase value, return a cl-vectors-style dash vector and TOGGLE-P value." (let ((sum (reduce #'+ dash-vector))) (when (or (zerop phase) (= phase sum)) ;; Don't bother doing anything for an empty phase (return-from apply-dash-phase (values dash-vector 0)))) (let ((index 0) (invertp t)) (flet ((next-value () (cond ((< index (length dash-vector)) (setf invertp (not invertp))) (t (setf invertp nil index 0))) (prog1 (aref dash-vector index) (incf index))) (join (&rest args) (apply 'concatenate 'vector (mapcar (lambda (thing) (if (vectorp thing) thing (vector thing))) args)))) (loop (let ((step (next-value))) (decf phase step) (when (not (plusp phase)) (let ((result (join (- phase) (subseq dash-vector index) dash-vector))) (when invertp (setf result (join 0 result))) (return (values result (- (length result) (length dash-vector))))))))))) (defun dash-paths (paths dash-vector dash-phase) (if dash-vector (multiple-value-bind (sizes cycle-index) (apply-dash-phase dash-vector dash-phase) (paths:dash-path paths sizes :cycle-index cycle-index)) paths)) (defun stroke-paths (paths &key line-width join-style cap-style) (mapcan (lambda (path) (paths:stroke-path path line-width :joint join-style :caps cap-style)) paths))
5,229
Common Lisp
.lisp
121
34.338843
81
0.615914
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e3f2d4798a50cbfe21286d4dc15aca3e6726259851f4e14fb7247cd47ebfd386
42,875
[ 249568 ]
42,876
test.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/test.lisp
(in-package #:vecto) (defun test (output-file) (with-canvas (:width 100 :height 100) (set-line-width 5.0) ;; red stroke (set-rgb-stroke 1 0 0) (move-to 10 10) (line-to 90 90) (stroke) ;; green stroke (set-rgb-stroke 0 1 0) (move-to 10 90) (line-to 90 10) (stroke) ;; blue+alpha transform stroke (set-rgba-stroke 0 0 1 0.5) (flet ((elbow (radians) (with-graphics-state (translate 50 50) (rotate radians) (scale 0.25 0.25) (move-to 0 0) (curve-to 0 100 0 100 100 100) (set-line-width 10.0) (stroke)))) (let* ((rotations 25) (step (/ (* pi 2) rotations))) (dotimes (i rotations) (elbow (* i step))))) (save-png output-file))) (defun test-rotate (output-file) (with-canvas (:width 100 :height 100) (translate 50 50) (move-to 0 0) (line-to 0 10) (rotate (- (/ pi 4))) (set-line-width 15) (stroke) (save-png output-file))) (defun test-skew (output-file) (with-canvas (:width 100 :height 100) (move-to 0 0) (line-to 0 75) (skew (- (/ pi 4)) (- (/ pi 4))) (set-line-width 15) (stroke) (save-png output-file))) (defun hole-test (file) (with-canvas (:width 100 :height 100) (translate 10 10) (scale 50 50) (set-line-width 0.1) (move-to 0 0) (line-to 0 1) (line-to 1 1) (line-to 1 0) (line-to 0 0) (move-to 0.1 0.8) (line-to 0.1 0.1) (line-to 0.8 0.1) (line-to 0.8 0.8) (line-to 0.1 0.8) (fill-path) (save-png file))) (defun rectangle-test (file) (with-canvas (:width 100 :height 100) (rectangle 10 10 50 50) (fill-path) (save-png file))) (defun rectangle-fill-test (file) (with-canvas (:width 5 :height 5) (set-rgba-fill 1 0 0 0.5) (rectangle 0 0 5 5) (fill-path) (save-png file))) (defun circle-test (string file) (with-canvas (:width 250 :height 180) (set-rgb-fill 1 1 1) (set-line-width 1) (translate 10 10) (centered-circle-path 0 0 5) (fill-and-stroke) (translate 15 15) (centered-circle-path 0 0 8) (fill-and-stroke) (translate 20 24) (centered-circle-path 0 0 11) (fill-and-stroke) (centered-ellipse-path 75 60 100 40) (fill-and-stroke) (let ((font (get-font "/home/xach/.fonts/vagron.ttf"))) (set-font font 25) (translate -5 50) (let ((bbox (string-bounding-box string font))) (set-line-width 1) (set-rgba-fill 1 0 0 0.5) (rectangle (xmin bbox) (ymin bbox) (- (xmax bbox) (xmin bbox)) (- (ymax bbox) (ymin bbox))) (fill-path)) (set-rgb-fill 0 1 0) (draw-string string)) (save-png file))) (defun center-test (string file) (with-canvas (:width 200 :height 100) (let ((font (get-font #p"times.ttf"))) (set-font font 36) (draw-centered-string 100 25 string) (set-rgba-fill 1 0 0 0.5) (set-rgb-stroke 0 0 0) (centered-circle-path 100 25 5) (stroke) (save-png file)))) (defun twittertext (string size font file) (zpb-ttf:with-font-loader (loader font) (let ((bbox (string-bounding-box string size loader))) (with-canvas (:width (- (ceiling (xmax bbox)) (floor (xmin bbox))) :height (- (ceiling (ymax bbox)) (floor (ymin bbox)))) (set-font loader size) (set-rgba-fill 1 1 1 0.1) (clear-canvas) (set-rgb-fill 0 0 0) (translate (- (xmin bbox)) (- (ymin bbox))) (draw-string 0 0 string) (save-png file))))) (defun arc-to (center-x center-y radius start extent) ;; An arc of extent zero will generate an error at bezarc (divide by zero). ;; This case may be given by two aligned points in a polyline. ;; Better do nothing. (unless (zerop extent) (if (<= (abs extent) (/ pi 2.0)) (multiple-value-bind (x1 y1 x2 y2 x3 y3) (bezarc center-x center-y radius start extent) (curve-to x1 y1 x2 y2 x3 y3)) (let ((half-extent (/ extent 2.0))) (arc-to center-x center-y radius start half-extent) (arc-to center-x center-y radius (+ start half-extent) half-extent))))) (defun bezarc (center-x center-y radius start extent) ;; start and extent should be in radians. ;; Returns first-control-point-x first-control-point-y ;; second-control-point-x second-control-point-y ;; end-point-x end-point-y (let* ((end (+ start extent)) (s-start (sin start)) (c-start (cos start)) (s-end (sin end)) (c-end (cos end)) (ang/2 (/ extent 2.0)) (kappa (* (/ 4.0 3.0) (/ (- 1 (cos ang/2)) (sin ang/2)))) (x1 (- c-start (* kappa s-start))) (y1 (+ s-start (* kappa c-start))) (x2 (+ c-end (* kappa s-end))) (y2 (- s-end (* kappa c-end)))) (values (+ (* x1 radius) center-x)(+ (* y1 radius) center-y) (+ (* x2 radius) center-x)(+ (* y2 radius) center-y) (+ (* c-end radius) center-x)(+ (* s-end radius) center-y)))) (defun degrees (degrees) (* (/ pi 180) degrees)) (defun arc-test (file) (with-canvas (:width 100 :height 100) (rotate-degrees 15) (translate 0 10) (set-line-width 10) (move-to 75 0) (arc-to 0 0 75 0 (degrees 15)) (stroke) (save-png file))) (defun rect-test (file) (with-canvas (:width 5 :height 5) (set-rgba-fill 1 0 0 0.5) (rectangle 0 0 5 5) (fill-path) (save-png file))) (defun text-test (&key string size font file) (with-canvas (:width 200 :height 200) (let ((loader (get-font font))) (set-rgb-fill 0.8 0.8 0.9) (clear-canvas) (set-font loader size) (set-rgb-fill 0.0 0.0 0.3) (scale 0.5 0.5) (rotate (* 15 (/ pi 180))) (draw-string 10 10 string) (save-png file)))) (defun dash-test (file) (with-canvas (:width 200 :height 200) (rectangle 10 10 125 125) (set-rgba-fill 0.3 0.5 0.9 0.5) (set-line-width 4) (set-dash-pattern #(10 10) 5) (fill-and-stroke) (save-png file))) (defun sign-test (string font file &key (font-size 72) (outer-border 2) (stripe-width 5) (inner-border 2) (corner-radius 10)) (zpb-ttf:with-font-loader (loader font) (let* ((bbox (string-bounding-box string font-size loader)) (text-height (ceiling (- (ymax bbox) (ymin bbox)))) (text-width (ceiling (- (xmax bbox) (xmin bbox)))) (stripe/2 (/ stripe-width 2.0)) (b1 (+ outer-border stripe/2)) (b2 (+ inner-border stripe/2)) (x0 0) (x1 (+ x0 b1)) (x2 (+ x1 b2)) (y0 0) (y1 (+ y0 b1)) (y2 (+ y1 b2)) (width (truncate (+ text-width (* 2 (+ b1 b2))))) (width1 (- width (* b1 2))) (height (truncate (+ text-height (* 2 (+ b1 b2))))) (height1 (- height (* b1 2)))) (with-canvas (:width width :height height) (set-rgb-fill 0.0 0.43 0.33) (set-rgb-stroke 0.95 0.95 0.95) ;; Stripe shadow + stripe (set-line-width stripe-width) (with-graphics-state (translate 2 -2) (set-rgba-stroke 0.0 0.0 0.0 0.3) (rounded-rectangle x1 y1 width1 height1 corner-radius corner-radius) (fill-and-stroke)) (rounded-rectangle x1 y1 width1 height1 corner-radius corner-radius) (set-dash-pattern #(10 20) 0) (stroke) ;; Text shadow & text (set-font loader font-size) (translate (- (xmin bbox)) (- (ymin bbox))) (with-graphics-state (translate 1 -1) (set-rgba-fill 0.0 0.0 0.0 1.0) (draw-string x2 y2 string)) (set-rgb-fill 0.95 0.95 0.95) (draw-string x2 y2 string) (save-png file))))) (defun fill-test (file) (with-canvas (:width 100 :height 100) (set-rgb-stroke 1 0 0) (set-rgb-fill 0 1 0) (move-to 0 0) (line-to 50 50) (line-to 100 10) (fill-and-stroke) (save-png file))) (defun circle-test (file) (with-canvas (:width 1000 :height 1000) (scale 5 10) (set-line-width 3) (centered-circle-path 50 50 45) (set-rgb-fill 1 1 0) (fill-and-stroke) (save-png file))) (defun test-gradient (file fun) (with-canvas (:width 500 :height 500) (with-graphics-state (set-gradient 100 100 1 0 0 1 200 235 0 1 0 1 :domain-function fun) (rectangle 0 0 500 500) (fill-path)) (with-graphics-state (set-rgba-stroke 1 1 1 0.5) (set-dash-pattern #(10 10) 0) (move-to 100 100) (line-to 200 235) (stroke)) (set-rgb-stroke 1 1 1) (centered-circle-path 100 100 10) (stroke) (set-rgb-stroke 0 0 0) (centered-circle-path 200 235 10) (stroke) (set-rgb-fill 1 1 1) (let* ((font (get-font #p"~/.fonts/cour.ttf")) (name (string-downcase fun)) (bbox (geometry:bbox-box (string-bounding-box name 24 font)))) (translate 200 300) (set-font font 24) (setf bbox (geometry:expand bbox 10)) (rectangle (geometry:xmin bbox) (geometry:ymin bbox) (geometry:width bbox) (geometry:height bbox)) (fill-and-stroke) (set-rgb-fill 0 0 0) (draw-string 0 0 (string-downcase fun)) (fill-path) (save-png file))))
9,611
Common Lisp
.lisp
295
25.430508
81
0.559922
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
7f7d75cf1b310e60a73d8f063efe1305d0de9cc3dc87877ded44526a609b4dc5
42,876
[ 383720 ]
42,877
examples.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/doc/examples.lisp
;;; Copyright (c) 2007 Zachary Beane, All Rights Reserved ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; $Id: examples.lisp,v 1.4 2007/10/01 19:57:15 xach Exp $ (defpackage #:vecto-examples (:use #:cl #:vecto)) (in-package #:vecto-examples) (defun radiant-lambda (file) (with-canvas (:width 90 :height 90) (let ((font (get-font "times.ttf")) (step (/ pi 7))) (set-font font 40) (translate 45 45) (draw-centered-string 0 -10 #(#x3BB)) (set-rgb-stroke 1 0 0) (centered-circle-path 0 0 35) (stroke) (set-rgba-stroke 0 0 1.0 0.5) (set-line-width 4) (dotimes (i 14) (with-graphics-state (rotate (* i step)) (move-to 30 0) (line-to 40 0) (stroke))) (save-png file)))) (defun feedlike-icon (file) (with-canvas (:width 100 :height 100) (set-rgb-fill 1.0 0.65 0.3) (rounded-rectangle 0 0 100 100 10 10) (fill-path) (set-rgb-fill 1.0 1.0 1.0) (centered-circle-path 20 20 10) (fill-path) (flet ((quarter-circle (x y radius) (move-to (+ x radius) y) (arc x y radius 0 (/ pi 2)))) (set-rgb-stroke 1.0 1.0 1.0) (set-line-width 15) (quarter-circle 20 20 30) (stroke) (quarter-circle 20 20 60) (stroke)) (rounded-rectangle 5 5 90 90 7 7) (set-gradient-fill 50 90 1.0 1.0 1.0 0.7 50 20 1.0 1.0 1.0 0.0) (set-line-width 2) (set-rgba-stroke 1.0 1.0 1.0 0.1) (fill-and-stroke) (save-png file))) (defun star-clipping (file) (with-canvas (:width 200 :height 200) (let ((size 100) (angle 0) (step (* 2 (/ (* pi 2) 5)))) (translate size size) (move-to 0 size) (dotimes (i 5) (setf angle (+ angle step)) (line-to (* (sin angle) size) (* (cos angle) size))) (even-odd-clip-path) (end-path-no-op) (flet ((circle (distance) (set-rgba-fill distance 0 0 (- 1.0 distance)) (centered-circle-path 0 0 (* size distance)) (fill-path))) (loop for i downfrom 1.0 by 0.05 repeat 20 do (circle i))) (save-png file)))) (defun gradient-example (file) (with-canvas (:width 200 :height 50) (set-gradient-fill 25 0 1 0 0 1 175 0 1 0 0 0) (rectangle 0 0 200 50) (fill-path) (save-png file))) (defun gradient-bilinear-example (file) (with-canvas (:width 200 :height 50) (set-gradient-fill 25 0 1 0 0 1 175 0 1 0 0 0 :domain-function 'bilinear-domain) (rectangle 0 0 200 50) (fill-path) (save-png file))) (defun text-paths (file) (with-canvas (:width 400 :height 100) (set-font (get-font "/tmp/font.ttf") 70) (centered-string-paths 200 15 "Hello, world!") (set-line-join :round) (set-line-cap :round) (set-line-width 3) (set-dash-pattern #(0 5) 0) (stroke-to-paths) (set-gradient-fill 0 0 1 0 0 0.5 0 100 1 1 1 1) (fill-path) (save-png file)))
4,549
Common Lisp
.lisp
129
28.116279
70
0.589075
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
cfb6c8b587cadff596dde78be79ad6be85e035af2d9f437b3e24005e032d8e42
42,877
[ 37542 ]
42,878
illustrations.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/doc/illustrations.lisp
;;;; $Id: illustrations.lisp,v 1.6 2007/10/01 16:24:10 xach Exp $ (defpackage #:vecto-illustrations (:use #:cl #:vecto)) (in-package #:vecto-illustrations) (defun x (point) (car point)) (defun y (point) (cdr point)) (defun annotated-path (&rest points) (with-graphics-state (set-rgb-stroke 0.5 0.5 0.5) (set-rgb-fill 0.5 0.5 0.5) (set-line-width 2) (dolist (point (remove-duplicates points :test 'equal)) (centered-circle-path (x point) (y point) 3)) (fill-path) (move-to (x (first points)) (y (first points))) (dolist (point (rest points)) (line-to (x point) (y point))) (stroke))) (defun join-style (style file) (with-canvas (:width 160 :height 165) (set-rgb-fill 1 1 1) (clear-canvas) (set-rgb-stroke 0 0 0) (set-line-width 20) (move-to 20 20) (line-to 80 140) (line-to 140 20) (set-line-join style) (stroke) (annotated-path '(20 . 20) '(80 . 140) '(140 . 20)) (save-png file))) (defun cap-style (style file) (with-canvas (:width 40 :height 100) (set-rgb-fill 1 1 1) (clear-canvas) (set-rgb-stroke 0 0 0) (set-line-width 20) (move-to 20 20) (line-to 20 80) (set-line-cap style) (stroke) (annotated-path '(20 . 20) '(20 . 80)) (save-png file))) (defun closed-subpaths (closep file) (with-canvas (:width 160 :height 160) (set-rgb-fill 1 1 1) (clear-canvas) (set-rgb-stroke 0 0 0) (set-line-width 20) (move-to 20 20) (line-to 20 140) (line-to 140 140) (line-to 140 20) (line-to 20 20) (when closep (close-subpath)) (stroke) (annotated-path '(20 . 20) '(20 . 140) '(140 . 140) '(140 . 20) '(20 . 20)) (save-png file))) (defun dash-paths (array phase cap-style file) (with-canvas (:width 160 :height 40) (set-rgb-fill 1 1 1) (clear-canvas) (set-rgb-stroke 0 0 0) (set-line-width 20) (with-graphics-state (set-dash-pattern array phase) (set-line-cap cap-style) (move-to 20 20) (line-to 140 20) (stroke)) (annotated-path '(20 . 20) '(140 . 20)) (save-png file))) (defun simple-clipping-path (file &key clip-circle clip-rounded-rectangle) (with-canvas (:width 100 :height 100) (let ((x0 45) (y 45) (r 40)) (set-rgb-fill 1 1 1) (clear-canvas) (with-graphics-state (set-rgb-fill 0.9 0.9 0.9) (rectangle 10 10 80 80) (fill-path)) (with-graphics-state (when clip-circle (centered-circle-path x0 y r) (clip-path) (end-path-no-op)) (when clip-rounded-rectangle (rounded-rectangle 45 25 50 50 10 10) (clip-path) (end-path-no-op)) (set-rgb-fill 1 0 0) (set-rgb-stroke 1 1 0) (rectangle 10 10 80 80) (fill-path)) (when clip-circle (with-graphics-state (set-rgb-stroke 0.5 0.5 0.5) (set-dash-pattern #(5) 0) (set-line-width 1) (centered-circle-path x0 y r) (stroke))) (when clip-rounded-rectangle (with-graphics-state (set-rgb-stroke 0.5 0.5 0.5) (set-dash-pattern #(5) 0) (set-line-width 1) (rounded-rectangle 45 25 50 50 10 10) (stroke))) (save-png file)))) (defun arc-demo (file) (flet ((point (x y) (with-graphics-state (set-rgb-fill 0 0 0) (centered-circle-path x y 3) (fill-path)))) (with-canvas (:width 150 :height 150) (translate 10 10) (let* ((theta1 (* (/ pi 180) 20)) (theta2 (* (/ pi 180) 80)) (theta3 (/ (+ theta1 theta2) 2)) (radius 120) (x1 (* (+ radius 10) (cos theta1))) (y1 (* (+ radius 10) (sin theta1))) (x2 (* (+ radius 10) (cos theta2))) (y2 (* (+ radius 10) (sin theta2)))) (with-graphics-state (set-rgb-stroke 0.5 0.5 0.5) (set-dash-pattern #(3 3) 0) (move-to 0 0) (line-to x1 y1) (stroke) (move-to 0 0) (line-to x2 y2) (stroke) (move-to -500 0) (line-to 500 0) (stroke)) (set-rgb-stroke 1 0 0) (set-line-width 1) (arc 0 0 80 0 theta1) (stroke) (set-rgb-stroke 0 0 1) (arc 0 0 100 0 theta2) (stroke) (set-rgb-stroke 0 1 0) (move-to 0 0) (line-to (* radius (cos theta3)) (* radius (sin theta3))) (stroke) (set-line-width 2) (set-rgb-stroke 0 0 0) (arc 0 0 radius theta1 theta2) (stroke) (point (* radius (cos theta1)) (* radius (sin theta1))) (point (* radius (cos theta2)) (* radius (sin theta2))) (save-png file))))) (defun pie-wedge (file) (with-canvas (:width 80 :height 60) (let ((x 0) (y 0) (radius 70) (angle1 (* (/ pi 180) 15)) (angle2 (* (/ pi 180) 45))) (translate 5 5) (set-rgb-fill 1 1 1) (move-to 0 0) (arc x y radius angle1 angle2) (fill-and-stroke) (save-png file)))) (defun wiper (file) (with-canvas (:width 70 :height 70) (let ((x 0) (y 0) (r1 30) (r2 60) (angle1 0) (angle2 (* (/ pi 180) 90))) (translate 5 5) (set-rgba-fill 1 1 1 0.75) (arc x y r1 angle1 angle2) (arcn x y r2 angle2 angle1) (fill-and-stroke) (save-png file)))) (defun make-illustrations () (cap-style :butt "cap-style-butt.png") (cap-style :square "cap-style-square.png") (cap-style :round "cap-style-round.png") (join-style :miter "join-style-miter.png") (join-style :bevel "join-style-bevel.png") (join-style :round "join-style-round.png") (closed-subpaths nil "open-subpath.png") (closed-subpaths t "closed-subpath.png") (dash-paths #() 0 :butt "dash-pattern-none.png") (dash-paths #(30 30) 0 :butt "dash-pattern-a.png") (dash-paths #(30 30) 15 :butt "dash-pattern-b.png") (dash-paths #(10 20 10 40) 0 :butt "dash-pattern-c.png") (dash-paths #(10 20 10 40) 13 :butt "dash-pattern-d.png") (dash-paths #(30 30) 0 :round "dash-pattern-e.png") (simple-clipping-path "clip-unclipped.png") (simple-clipping-path "clip-to-circle.png" :clip-circle t) (simple-clipping-path "clip-to-rectangle.png" :clip-rounded-rectangle t) (simple-clipping-path "clip-to-both.png" :clip-circle t :clip-rounded-rectangle t))
6,740
Common Lisp
.lisp
214
23.752336
74
0.54377
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
d0995d266191cfac30437100c357d6fee6574227366907c67e890da4c1b4d1bb
42,878
[ 345007 ]
42,879
box.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/box.lisp
;;;; box.lisp (in-package #:vecto-geometry) (defclass box () ((xmin :initarg :xmin :accessor xmin) (ymin :initarg :ymin :accessor ymin) (xmax :initarg :xmax :accessor xmax) (ymax :initarg :ymax :accessor ymax))) (defmethod initialize-instance :before ((box box) &key xmin ymin xmax ymax) (assert (<= xmin xmax)) (assert (<= ymin ymax))) (defmethod xmin ((point point)) (x point)) (defmethod xmax ((point point)) (x point)) (defmethod ymin ((point point)) (y point)) (defmethod ymax ((point point)) (y point)) (defmethod print-object ((object box) stream) (print-unreadable-object (object stream :type t) (format stream "~A,~A ~A,~A" (xmin object) (ymin object) (xmax object) (ymax object)))) (defun box (xmin ymin xmax ymax) (make-instance 'box :xmin xmin :ymin ymin :xmax xmax :ymax ymax)) (defun point-box (a b) "Creates the smallest box that contains the points A and B." (box (min (x a) (x b)) (min (y a) (y b)) (max (x a) (x b)) (max (y a) (y b)))) (defun origin-box (point) "Creates a bounding box that includes both the origin and POINT." (point-box *origin* point)) (defun bbox-box (bbox) "Creates a box from the BBOX vector." (box (aref bbox 0) (aref bbox 1) (aref bbox 2) (aref bbox 3))) (defgeneric minpoint (box) (:method ((box box)) (point (xmin box) (ymin box)))) (defgeneric maxpoint (box) (:method ((box box)) (point (xmax box) (ymax box)))) (defgeneric centerpoint (box) (:method ((box box)) (midpoint (minpoint box) (maxpoint box)))) (defgeneric width (object) (:method (object) (- (xmax object) (xmin object)))) (defgeneric height (object) (:method (object) (- (ymax object) (ymin object)))) (defgeneric area (box) (:method ((box box)) (* (width box) (height box)))) (defgeneric emptyp (box) (:method ((box box)) ;; A little more efficient than (zerop (area box)) (or (= (xmax box) (xmin box)) (= (ymax box) (ymin box))))) (defun contract (box amount) (let ((p (point amount amount))) (point-box (add (minpoint box) p) (sub (maxpoint box) p)))) (defun expand (box amount) (contract box (- amount))) (defun %point-box-add (point box) (point-box (add (minpoint box) point) (add (maxpoint box) point))) (defmethod add/2 ((point point) (box box)) (%point-box-add point box)) (defmethod add/2 ((box box) (point point)) (%point-box-add point box)) (defun %point-box-mul (point box) (point-box (mul (minpoint box) point) (mul (maxpoint box) point))) (defmethod mul ((point point) (box box)) (%point-box-mul point box)) (defmethod mul ((box box) (point point)) (%point-box-mul point box)) (defmethod sub ((box box) (point point)) (point-box (sub (minpoint box) point) (sub (maxpoint box) point))) (defmethod div ((box box) (point point)) (point-box (div (minpoint box) point) (div (maxpoint box) point))) (defmethod eqv ((a box) (b box)) (and (= (xmin a) (xmin b)) (= (xmax a) (xmax b)) (= (ymin a) (ymin b)) (= (ymax a) (ymax b)))) (defgeneric displace (box point) (:method ((box box) point) (point-box (add (minpoint box) point) (add (maxpoint box) point)))) (defmethod scale ((box box) (scaler number)) (point-box (scale (minpoint box) scaler) (scale (maxpoint box) scaler))) (defgeneric bounding-box-delegate (object) (:documentation "An object that provides the bounding box for some other object.")) (defgeneric bounding-box (object) (:method (object) (bounding-box (bounding-box-delegate object))) (:method ((box box)) box) (:method ((point point)) (point-box point point)) (:method ((objects sequence)) (reduce #'combine (map 'vector #'bounding-box objects)))) (defun transpose (box) (point-box (minpoint box) (point (ymax box) (xmax box)))) (defun containsp (box point) (and (<= (xmin box) (x point) (xmax box)) (<= (ymin box) (y point) (ymax box)))) ;;; TODO: ;;; ;;; overlapsp box box ;;; containsp box point ;;;
4,294
Common Lisp
.lisp
137
26.277372
70
0.609572
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5d08b254f8f00cd7b95ceeaaed741d2c03137297cce18bed7aa365a4de7088dc
42,879
[ 42221 ]
42,880
box-text.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/box-text.lisp
;;;; boxtext.lisp (in-package #:vectometry) (defparameter *horizontal-alignments* #(:before :left :center :right :after)) (defparameter *vertical-alignments* #(:below :bottom :middle :top :atop)) (defun rotate-alignment (horizontal vertical rotation) (let ((h (position horizontal *horizontal-alignments*)) (v (position vertical *vertical-alignments*))) (flet ((invert (i) (- (length *horizontal-alignments*) i 1))) (unless h (error "Invalid horizontal alignment ~S" horizontal)) (unless v (error "Invalid vertical alignment ~S" vertical)) (ecase rotation (:none) (:right (psetf h (invert v) v h)) (:left (psetf v (invert h) h v)) (:invert (psetf h (invert h) v (invert v)))) (values (aref *horizontal-alignments* h) (aref *vertical-alignments* v))))) (defun draw-box-text (box text &key size loader (horizontal :left) (vertical :bottom) (rotation :none)) (let ((stringbox (string-bounding-box text size loader)) (x (xmin box)) (y (ymin box)) (center (centerpoint box))) (flet ((handle-rotation (point degrees h v) (with-graphics-state (translate point) (rotate-degrees degrees) (let ((box* (if (= degrees 180) box (transpose box)))) (setf box* (displace box* (neg (minpoint box)))) (return-from draw-box-text (draw-box-text box* text :size size :loader loader :horizontal h :vertical v :rotation :none)))))) (ecase rotation (:none) (:left (multiple-value-bind (h v) (rotate-alignment horizontal vertical rotation) (handle-rotation (bottom-right box) 90 h v))) (:right (multiple-value-bind (h v) (rotate-alignment horizontal vertical rotation) (handle-rotation (top-left box) -90 h v))) (:invert (multiple-value-bind (h v) (rotate-alignment horizontal vertical rotation) (handle-rotation (maxpoint box) 180 h v)))) (ecase horizontal (:before (setf x (- (xmin box) (width stringbox)))) (:left) (:center (setf x (- (x center) (/ (width stringbox) 2)))) (:right (setf x (- (xmax box) (xmax stringbox)))) (:after (setf x (xmax box)))) (ecase vertical (:atop (setf y (ymax box))) (:top (setf y (- (ymax box) size))) (:middle (setf y (- (y center) (/ size 2)))) (:bottom) (:below (setf y (- (ymin box) size)))) (let ((origin (point x y))) (draw-string origin text))))) #+nil (defun testo (file) (with-box-canvas (box 0 0 800 800) (let ((tbox (box 50 50 700 500)) (font (get-font "~/Documents/Marydale.ttf"))) (set-font font 18) (set-stroke-color (hsv-color 1 1 1)) (rectangle tbox) (stroke) (draw-box-text tbox "CENTER ATOP" :size 18 :loader font :horizontal :center :vertical :atop :rotation :invert) (draw-box-text tbox "AFTER BELOW" :size 18 :loader font :horizontal :after :vertical :below) (save-png file))))
3,490
Common Lisp
.lisp
89
28.303371
70
0.532705
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
ca21a4e2ec04a0d9cf2c1fb96acdc8181268519201ec36cea826c6288ee1f8dc
42,880
[ 411359 ]
42,881
package.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/package.lisp
;;;; package.lisp (defpackage #:vecto-geometry (:use #:cl) (:export #:point #:coordinates #:apoint #:xpoint #:ypoint #:x #:y #:*origin* #:midpoint #:eqv #:add #:sub #:mul #:div #:neg #:abs* #:angle #:distance #:scale #:box #:bbox-box #:point-box #:origin-box #:bounding-box #:bounding-box-delegate #:displace #:transpose #:xmin #:ymin #:xmax #:ymax #:centerpoint #:maxpoint #:minpoint #:combine #:contract #:expand #:area #:emptyp #:containsp #:width #:height #:*identity-matrix* #:transform-matrix #:translation-matrix #:scaling-matrix #:rotation-matrix #:skewing-matrix #:transform #:transform-function)) (defpackage #:vectometry (:use #:cl) (:use #:vecto-geometry #:vecto) (:shadowing-import-from #:vecto-geometry #:scale) (:shadow ;; vecto wrappers #:move-to #:line-to #:curve-to #:quadratic-to #:draw-centered-string #:draw-string #:string-paths #:centered-string-paths #:string-bounding-box #:arc #:arcn #:rectangle #:rounded-rectangle #:centered-ellipse-path #:centered-circle-path #:set-gradient-fill #:translate ) (:export ;; colors #:rgb-color #:rgba-color #:hsv-color #:red #:green #:blue #:alpha #:rgb-values #:hsv-values #:gray-color #:graya-color #:*black* #:*white* #:html-code #:html-color #:add-alpha #:set-fill-color #:set-stroke-color ;; extended geometry #:top-left #:bottom-left #:top-right #:bottom-right #:northpoint #:northeastpoint #:eastpoint #:southeastpoint #:southpoint #:southwestpoint #:westpoint #:northwestpoint #:with-box-canvas ;; re-exported geometry bits #:point #:apoint #:xpoint #:ypoint #:x #:y #:*origin* #:midpoint #:eqv #:add #:sub #:mul #:div #:neg #:abs* #:angle #:distance #:box #:scale #:bbox-box #:point-box #:origin-box #:bounding-box #:displace #:xmin #:ymin #:xmax #:ymax #:centerpoint #:maxpoint #:minpoint #:combine #:contract #:expand #:area #:emptyp #:containsp #:width #:height #:*identity-matrix* #:transform-matrix #:translation-matrix #:scaling-matrix #:rotation-matrix #:skewing-matrix #:transform #:transform-function ;; re-exported vecto bits #:with-canvas #:with-graphics-state #:clear-canvas #:save-png #:save-png-stream ;; path construction #:move-to #:line-to #:curve-to #:quadratic-to #:close-subpath #:stroke-to-paths #:arc #:arcn ;; Clipping #:end-path-no-op #:clip-path #:even-odd-clip-path ;; path construction one-offs #:rectangle #:rounded-rectangle #:centered-ellipse-path #:centered-circle-path #:+kappa+ ;; painting #:fill-path #:even-odd-fill #:stroke #:fill-and-stroke #:even-odd-fill-and-stroke ;; graphics state #:with-graphics-state #:set-line-cap #:set-line-join #:set-line-width #:set-dash-pattern #:set-rgba-stroke #:set-rgb-stroke #:set-rgba-fill #:set-rgb-fill #:set-gradient-fill #:linear-domain #:bilinear-domain ;; graphics state coordinate transforms #:translate #:rotate #:rotate-degrees #:skew ;; text #:get-font #:set-font #:draw-string #:string-paths #:draw-centered-string #:centered-string-paths #:string-bounding-box #:draw-box-text)) (in-package #:vectometry)
3,844
Common Lisp
.lisp
196
14.091837
47
0.571507
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
38394f40cdebe1d8db98f464f55d0140d9cc5c542b975caa03e50b2e5a82dfc4
42,881
[ 115481 ]
42,882
vectometry.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/vectometry.lisp
;;;; vectometry.lisp (in-package #:vectometry) (defun move-to (p) (vecto:move-to (x p) (y p))) (defun line-to (p) (vecto:line-to (x p) (y p))) (defun curve-to (control1 control2 end) (vecto:curve-to (x control1) (y control1) (x control2) (y control2) (x end) (y end))) (defun quadratic-to (control end) (vecto:quadratic-to (x control) (y control) (x end) (y end))) (defun draw-string (p string) (vecto:draw-string (x p) (y p) string)) (defun draw-centered-string (p string) (vecto:draw-centered-string (x p) (y p) string)) (defun string-paths (p string) (vecto:string-paths (x p) (y p) string)) (defun string-bounding-box (string size loader) (bbox-box (vecto:string-bounding-box string size loader))) (defun arc (center radius theta1 theta2) (vecto:arc (x center) (y center) radius theta1 theta2)) (defun arcn (center radius theta1 theta2) (vecto:arcn (x center) (y center) radius theta1 theta2)) (defun rectangle (box) (vecto:rectangle (xmin box) (ymin box) (width box) (height box))) (defun rounded-rectangle (box rx ry) (vecto:rounded-rectangle (xmin box) (ymin box) (width box) (height box) rx ry)) (defun centered-ellipse-path (center rx ry) (vecto:centered-ellipse-path (x center) (y center) rx ry)) (defun centered-circle-path (center radius) (vecto:centered-circle-path (x center) (y center) radius)) (defun translate (point) (vecto:translate (x point) (y point))) (defmacro with-box-canvas (box &body body) (let ((box* (gensym "BOX"))) `(let* ((,box* ,box)) (with-canvas (:width (ceiling (width ,box*)) :height (ceiling (height ,box*))) (let ((p (neg (minpoint ,box*)))) (translate (point (ceiling (x p)) (ceiling (y p))))) ,@body)))) (defgeneric top-left (object) (:method (object) (let ((box (bounding-box object))) (point (xmin box) (ymax box))))) (defgeneric top-right (object) (:method (object) (maxpoint (bounding-box object)))) (defgeneric bottom-left (object) (:method (object) (minpoint (bounding-box object)))) (defgeneric bottom-right (object) (:method (object) (let ((box (bounding-box object))) (point (xmax box) (ymin box))))) (macrolet ((compass-point-method (name component1 &optional component2) (if component2 `(defgeneric ,name (object) (:method (object) (midpoint (,component1 object) (,component2 object)))) `(defgeneric ,name (object) (:method (object) (,component1 object)))))) (compass-point-method northpoint top-left top-right) (compass-point-method northeastpoint top-right) (compass-point-method eastpoint top-right bottom-right) (compass-point-method southeastpoint bottom-right) (compass-point-method southpoint bottom-left bottom-right) (compass-point-method southwestpoint bottom-left) (compass-point-method westpoint bottom-left top-left) (compass-point-method northwestpoint top-left)) (defun set-gradient-fill (p1 c1 p2 c2 &key (extend-start t) (extend-end t) (domain-function 'vecto:linear-domain)) (vecto:set-gradient-fill (x p1) (y p1) (red c1) (green c1) (blue c1) (alpha c1) (x p2) (y p2) (red c2) (green c2) (blue c2) (alpha c2) :extend-start extend-start :extend-end extend-end :domain-function domain-function)) (defmethod bounding-box ((glyph zpb-ttf::glyph)) (bbox-box (zpb-ttf:bounding-box glyph)))
3,865
Common Lisp
.lisp
89
34.550562
71
0.600694
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
38697976167233b0675450d5bdaad1f5dbb92de0ec672e2eecffc60f379a86e2
42,882
[ 87294 ]
42,883
colors.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/colors.lisp
;;;; colors.lisp (in-package #:vectometry) (defclass color () ((red :initarg :red :accessor red) (green :initarg :green :accessor green) (blue :initarg :blue :accessor blue))) (defun rgb-color (r g b) (make-instance 'color :red r :green g :blue b)) (defclass color/alpha (color) ((alpha :initarg :alpha :accessor alpha))) (defun rgba-color (r g b a) (make-instance 'color/alpha :red r :green g :blue b :alpha a)) ;;; from kmrcl (defun rgb->hsv (r g b) (let* ((min (min r g b)) (max (max r g b)) (delta (- max min)) (v max) (s 0) (h nil)) (when (plusp max) (setq s (/ delta max))) (when (plusp delta) (setq h (cond ((= max r) (nth-value 0 (/ (- g b) delta))) ((= max g) (nth-value 0 (+ 2 (/ (- b r) delta)))) (t (nth-value 0 (+ 4 (/ (- r g) delta)))))) (setq h (* 60 h)) (when (minusp h) (incf h 360))) (values h s v))) (defun hsv->rgb (h s v) (when (zerop s) (return-from hsv->rgb (values v v v))) (loop while (minusp h) do (incf h 360)) (loop while (>= h 360) do (decf h 360)) (let ((h-pos (/ h 60))) (multiple-value-bind (h-int h-frac) (truncate h-pos) (declare (fixnum h-int)) (let ((p (* v (- 1 s))) (q (* v (- 1 (* s h-frac)))) (t_ (* v (- 1 (* s (- 1 h-frac))))) r g b) (cond ((zerop h-int) (setf r v g t_ b p)) ((= 1 h-int) (setf r q g v b p)) ((= 2 h-int) (setf r p g v b t_)) ((= 3 h-int) (setf r p g q b v)) ((= 4 h-int) (setf r t_ g p b v)) ((= 5 h-int) (setf r v g p b q))) (values r g b))))) (defun hsv-color (h s v) (multiple-value-call 'rgb-color (hsv->rgb h s v))) (defgeneric hsv-values (color) (:method ((color color)) (rgb->hsv (red color) (green color) (blue color)))) (defgeneric rgb-values (color) (:method ((color color)) (values (red color) (green color) (blue color)))) (defgeneric darkp (color) (:method (color) (multiple-value-bind (hue saturation value) (hsv-values color) (or (< value 0.64) (and (< 0.5 saturation) (or (< hue 45) (< 205 hue))))))) (defvar *black* (rgb-color 0 0 0)) (defvar *white* (rgb-color 1 1 1)) (defun contrasting-text-color (color) (if (darkp color) *white* *black*)) (defun add-alpha (color alpha) (multiple-value-call #'rgba-color (rgb-values color) alpha)) (defun float-octet (float) "Convert a float in the range 0.0 - 1.0 to an octet." (values (round (* float 255.0d0)))) (defgeneric html-code (color) (:method (color) (format nil "#~2,'0X~2,'0X~2,'0X" (float-octet (red color)) (float-octet (green color)) (float-octet (blue color))))) (defmethod alpha ((color color)) 1.0) (defun set-fill-color (color) (vecto:set-rgba-fill (red color) (green color) (blue color) (alpha color))) (defun set-stroke-color (color) (vecto:set-rgba-stroke (red color) (green color) (blue color) (alpha color))) (defun html-color (code) (multiple-value-bind (size divisor) (ecase (length code) (7 (values 2 255.0)) (4 (values 1 15.0))) (flet ((value-at (i) (let* ((start (1+ (* i size))) (end (+ start size))) (/ (parse-integer code :start start :end end :radix 16) divisor)))) (rgb-color (value-at 0) (value-at 1) (value-at 2))))) (defun gray-color (value) (rgb-color value value value)) (defun graya-color (value alpha) (rgba-color value value value alpha))
4,131
Common Lisp
.lisp
141
20.964539
70
0.487639
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
e0d88766756add4032c0a933157f48835d0d16479856eccc5044dea2074cc2b4
42,883
[ 432404 ]
42,884
matrix.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/matrix.lisp
;;;; matrix.lisp (in-package #:vecto-geometry) (defclass transform-matrix () ((x-scale :initarg :x-scale :accessor x-scale) (y-skew :initarg :y-skew :accessor y-skew) (x-skew :initarg :x-skew :accessor x-skew) (y-scale :initarg :y-scale :accessor y-scale) (x-offset :initarg :x-offset :accessor x-offset) (y-offset :initarg :y-offset :accessor y-offset)) (:default-initargs :x-scale 1.0 :y-skew 0.0 :x-skew 0.0 :y-scale 1.0 :x-offset 0.0 :y-offset 0.0)) (defmethod print-object ((matrix transform-matrix) stream) (print-unreadable-object (matrix stream :type t) (format stream "~F ~F ~F ~F ~F ~F" (x-scale matrix) (y-skew matrix) (x-skew matrix) (y-scale matrix) (x-offset matrix) (y-offset matrix)))) (defun transform-matrix (a b c d e f) (make-instance 'transform-matrix :x-scale a :y-skew b :x-skew c :y-scale d :x-offset e :y-offset f)) (defvar *identity-matrix* (make-instance 'transform-matrix)) (defmacro transform-matrix-bind (lambda-list matrix &body body) (when (/= (length lambda-list) 6) (error "Bad lambda-list for MATRIX-BIND: 6 arguments required")) (let ((mat (gensym)) (slots '(x-scale y-skew x-skew y-scale x-offset y-offset))) `(let ((,mat ,matrix)) (let (,@(loop for slot in slots for var in lambda-list collect (list var `(,slot ,mat)))) ,@body)))) (defgeneric transform-function (transform-matrix) (:method ((matrix transform-matrix)) (transform-matrix-bind (a b c d e f) matrix (lambda (point) (let ((x (x point)) (y (y point))) (point (+ (* a x) (* c y) e) (+ (* b x) (* d y) f))))))) (defgeneric transform (point matrix) (:method (point (matrix transform-matrix)) (funcall (transform-function matrix) point))) (defmethod mul ((m1 transform-matrix) (m2 transform-matrix)) (transform-matrix-bind (a b c d e f) m1 (transform-matrix-bind (a* b* c* d* e* f*) m2 (transform-matrix (+ (* a a*) (* b c*)) (+ (* a b*) (* b d*)) (+ (* c a*) (* d c*)) (+ (* c b*) (* d d*)) (+ (* e a*) (* f c*) e*) (+ (* e b*) (* f d*) f*))))) (defun translation-matrix (tx ty) (transform-matrix 1 0 0 1 tx ty)) (defun scaling-matrix (sx sy) (transform-matrix sx 0 0 sy 0 0)) (defun rotation-matrix (theta) (let ((cos (cos theta)) (sin (sin theta))) (transform-matrix cos sin (- sin) cos 0 0))) (defun skewing-matrix (alpha beta) (transform-matrix 1 (tan alpha) (tan beta) 1 0 0))
3,091
Common Lisp
.lisp
97
22.505155
68
0.50218
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a131797770e4ef425c70eaf4718ddd9648246a4fd1aa08a9491f64aec3d12fa1
42,884
[ 27250 ]
42,885
operations.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/operations.lisp
;;;; operations.lisp (in-package #:vecto-geometry) (defgeneric combine (a b) (:method (a b) (box (min (xmin a) (xmin b)) (min (ymin a) (ymin b)) (max (xmax a) (xmax b)) (max (ymax a) (ymax b)))) (:method ((a null) b) (box (xmin b) (ymin b) (xmax b) (ymax b))) (:method (a (b null)) (box (xmin a) (ymin a) (xmax a) (ymax a))))
391
Common Lisp
.lisp
14
22.285714
34
0.501333
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
ee05d6c5ca9216026cb41581c88ebdfadab0974c1a81a162257e56186a64d645
42,885
[ 184127 ]
42,886
point.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/vecto-1.6/vectometry/point.lisp
;;;; point.lisp (in-package #:vecto-geometry) (defclass point () ((x :initarg :x :accessor x) (y :initarg :y :accessor y))) (defmethod print-object ((point point) stream) (print-unreadable-object (point stream :type t) (format stream "~A,~A" (x point) (y point)))) (defun point (x y) (make-instance 'point :x x :y y)) (defun coordinates (point) (values (x point) (y point))) (defun xpoint (x) (point x 0)) (defun ypoint (y) (point 0 y)) (defun apoint (angle distance) (point (* distance (cos angle)) (* distance (sin angle)))) (defgeneric midpoint (a b) (:method (a b) (point (/ (+ (x a) (x b)) 2) (/ (+ (y a) (y b)) 2)))) (defgeneric eqv (a b) (:method (a b) (and (= (x a) (x b)) (= (y a) (y b))))) (defgeneric add (a b &rest args) (:method (a b &rest args) (if args (reduce #'add/2 args :initial-value (add/2 a b)) (add/2 a b)))) (macrolet ((define-point-op (name operation) `(defgeneric ,name (a b) (:method ((a point) (b point)) (point (,operation (x a) (x b)) (,operation (y a) (y b))))))) (define-point-op add/2 +) (define-point-op sub -) (define-point-op mul *) (define-point-op div /)) (defgeneric neg (object) (:method ((point point)) (point (- (x point)) (- (y point))))) (defgeneric distance (p1 p2) (:method ((p1 point) (p2 point)) (let ((diff (sub p1 p2))) (sqrt (+ (* (x diff) (x diff)) (* (y diff) (y diff))))))) (defgeneric abs* (object) (:method ((point point)) (point (abs (x point)) (abs (y point))))) (defgeneric angle (p1 p2) (:method ((p1 point) (p2 point)) (let* ((diff (sub p2 p1)) (x (x diff)) (y (y diff))) (if (zerop x) (if (plusp y) (/ pi 2) (* 3 (/ pi 2))) (atan y x))))) (defgeneric scale (object scalar) (:method ((point point) scalar) (point (* (x point) scalar) (* (y point) scalar)))) (defvar *origin* (point 0 0))
2,109
Common Lisp
.lisp
73
22.958904
56
0.524093
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
010fb4d3450e01d1955472c61740737d86fe2389d461b896a4d1437a4d7f3104
42,886
[ 444271 ]
42,887
xsubseq.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/xsubseq-20170830-git/src/xsubseq.lisp
(in-package :cl-user) (defpackage xsubseq (:use :cl) #+(or sbcl openmcl cmu allegro) (:import-from #+sbcl :sb-cltl2 #+openmcl :ccl #+cmu :ext #+allegro :sys :variable-information) (:export :xsubseq :octets-xsubseq :string-xsubseq :concatenated-xsubseqs :null-concatenated-xsubseqs :octets-concatenated-xsubseqs :string-concatenated-xsubseqs :make-concatenated-xsubseqs :xlength :xnconc :xnconcf :coerce-to-sequence :coerce-to-string :with-xsubseqs)) (in-package :xsubseq) (deftype octets (&optional (len '*)) `(simple-array (unsigned-byte 8) (,len))) (defstruct (xsubseq (:constructor make-xsubseq (data start &optional (end (length data)) &aux (len (- end start))))) (data nil) (start 0 :type integer) (end 0 :type integer) (len 0 :type integer)) (defstruct (octets-xsubseq (:include xsubseq) (:constructor make-octets-xsubseq (data start &optional (end (length data)) &aux (len (- end start)))))) (defstruct (string-xsubseq (:include xsubseq) (:constructor make-string-xsubseq (data start &optional (end (length data)) &aux (len (- end start)))))) (defstruct (concatenated-xsubseqs (:constructor %make-concatenated-xsubseqs)) (len 0 :type integer) (last nil :type list) (children nil :type list)) (defun make-concatenated-xsubseqs (&rest children) (if (null children) (make-null-concatenated-xsubseqs) (%make-concatenated-xsubseqs :children children :last (last children) :len (reduce #'+ children :key #'xsubseq-len :initial-value 0)))) (defstruct (null-concatenated-xsubseqs (:include concatenated-xsubseqs))) (defstruct (octets-concatenated-xsubseqs (:include concatenated-xsubseqs))) (defstruct (string-concatenated-xsubseqs (:include concatenated-xsubseqs))) (defun xsubseq (data start &optional (end (length data))) (typecase data (octets (make-octets-xsubseq data start end)) (string (make-string-xsubseq data start end)) (t (make-xsubseq data start end)))) #+(or sbcl openmcl cmu allegro) (define-compiler-macro xsubseq (&whole form &environment env data start &optional end) (let ((type (cond ((constantp data) (type-of data)) ((and (symbolp data) (assoc 'type (nth-value 2 (variable-information data env))))) ((and (listp data) (eq (car data) 'make-string)) 'string) ((and (listp data) (eq (car data) 'the) (cadr data))) ((and (listp data) (eq (car data) 'make-array) (null (cadr (member :adjustable data))) (null (cadr (member :fill-pointer data))) (cadr (member :element-type data)))))) (g-data (gensym "DATA"))) (if (null type) form (cond ((subtypep type 'octets) `(let ((,g-data ,data)) (make-octets-xsubseq ,g-data ,start ,(or end `(length ,g-data))))) ((subtypep type 'string) `(let ((,g-data ,data)) (make-string-xsubseq ,g-data ,start ,(or end `(length ,g-data))))) (t form))))) (defun %xnconc2 (seq1 seq2) (flet ((seq-values (seq) (if (concatenated-xsubseqs-p seq) (values (concatenated-xsubseqs-children seq) (concatenated-xsubseqs-last seq) (concatenated-xsubseqs-len seq)) (let ((children (list seq))) (values children children (xsubseq-len seq)))))) (macrolet ((make-concatenated (type seq1 seq2) `(multiple-value-bind (children last len) (seq-values ,seq2) (,(cond ((eq type 'octets) 'make-octets-concatenated-xsubseqs) ((eq type 'string) 'make-string-concatenated-xsubseqs) (t '%make-concatenated-xsubseqs)) :len (+ (xsubseq-len ,seq1) len) :children (cons ,seq1 children) :last last)))) (etypecase seq1 (null-concatenated-xsubseqs seq2) (concatenated-xsubseqs (multiple-value-bind (children last len) (seq-values seq2) (if (concatenated-xsubseqs-last seq1) (progn (rplacd (concatenated-xsubseqs-last seq1) children) (setf (concatenated-xsubseqs-last seq1) last) (incf (concatenated-xsubseqs-len seq1) len)) ;; empty concatenated-xsubseqs (progn (setf (concatenated-xsubseqs-children seq1) children (concatenated-xsubseqs-len seq1) len (concatenated-xsubseqs-last seq1) last))) seq1)) (octets-xsubseq (make-concatenated octets seq1 seq2)) (string-xsubseq (make-concatenated string seq1 seq2)) (xsubseq (make-concatenated t seq1 seq2)))))) (defun xnconc (subseq &rest more-subseqs) (reduce #'%xnconc2 more-subseqs :initial-value subseq)) (define-modify-macro xnconcf (subseq &rest more-subseqs) xnconc) (defun xlength (seq) (etypecase seq (xsubseq (xsubseq-len seq)) (concatenated-xsubseqs (concatenated-xsubseqs-len seq)))) (defun coerce-to-sequence (seq) (etypecase seq (octets-concatenated-xsubseqs (octets-concatenated-xsubseqs-to-sequence seq)) (string-concatenated-xsubseqs (string-concatenated-xsubseqs-to-sequence seq)) (concatenated-xsubseqs (concatenated-xsubseqs-to-sequence seq)) (xsubseq (xsubseq-to-sequence seq)))) #+(or sbcl openmcl cmu allegro) (define-compiler-macro coerce-to-sequence (&whole form &environment env seq) (let ((type (cond ((constantp seq) (type-of seq)) ((and (symbolp seq) (assoc 'type (nth-value 2 (variable-information seq env))))) ((and (listp seq) (eq (car seq) 'the) (cadr seq)))))) (if (null type) form (cond ((subtypep type 'octets-concatenated-xsubseqs) `(octets-concatenated-xsubseqs-to-sequence ,seq)) ((subtypep type 'string-concatenated-xsubseqs) `(string-concatenated-xsubseqs-to-sequence ,seq)) ((subtypep type 'concatenated-xsubseqs) `(concatenated-xsubseqs-to-sequence ,seq)) ((subtypep type 'xsubseq) `(xsubseq-to-sequence ,seq)) (t form))))) (defun coerce-to-string (seq) (etypecase seq (null-concatenated-xsubseqs "") (octets-concatenated-xsubseqs (octets-concatenated-xsubseqs-to-string seq)) (string-concatenated-xsubseqs (string-concatenated-xsubseqs-to-sequence seq)) (octets-xsubseq (octets-xsubseq-to-string seq)) (string-xsubseq (xsubseq-to-sequence seq)))) #+(or sbcl openmcl cmu allegro) (define-compiler-macro coerce-to-string (&whole form &environment env seq) (let ((type (cond ((constantp seq) (type-of seq)) ((and (symbolp seq) (assoc 'type (nth-value 2 (variable-information seq env))))) ((and (listp seq) (eq (car seq) 'the) (cadr seq)))))) (if (null type) form (cond ((subtypep type 'octets-concatenated-xsubseqs) `(octets-concatenated-xsubseqs-to-string ,seq)) ((subtypep type 'string-concatenated-xsubseqs) `(string-concatenated-xsubseqs-to-sequence ,seq)) ((subtypep type 'octets-xsubseq) `(octets-xsubseq-to-string ,seq)) ((subtypep type 'string-xsubseq) `(xsubseq-to-sequence ,seq)) (t form))))) (defun xsubseq-to-sequence (seq) (let ((result (make-array (xsubseq-len seq) :element-type (array-element-type (xsubseq-data seq))))) (replace result (xsubseq-data seq) :start2 (xsubseq-start seq) :end2 (xsubseq-end seq)) result)) (defun octets-xsubseq-to-string (seq) (let ((result (make-array (xsubseq-len seq) :element-type 'character))) (declare (type simple-string result)) (let ((data (xsubseq-data seq)) (end (xsubseq-end seq))) (do ((i (xsubseq-start seq) (1+ i)) (j 0 (1+ j))) ((= i end) result) (setf (aref result j) (code-char (the (unsigned-byte 8) (aref (the octets data) i)))))))) (defun concatenated-xsubseqs-to-sequence (seq) (let ((result (make-array (concatenated-xsubseqs-len seq) :element-type (array-element-type (xsubseq-data (car (concatenated-xsubseqs-children seq))))))) (loop with current-pos = 0 for seq in (concatenated-xsubseqs-children seq) do (replace result (xsubseq-data seq) :start1 current-pos :start2 (xsubseq-start seq) :end2 (xsubseq-end seq)) (incf current-pos (xsubseq-len seq))) result)) (defun octets-concatenated-xsubseqs-to-sequence (seq) (let ((result (make-array (concatenated-xsubseqs-len seq) :element-type '(unsigned-byte 8)))) (declare (type octets result)) (loop with current-pos of-type integer = 0 for seq in (concatenated-xsubseqs-children seq) do (replace result (the octets (xsubseq-data seq)) :start1 current-pos :start2 (xsubseq-start seq) :end2 (xsubseq-end seq)) (incf current-pos (xsubseq-len seq))) result)) (defun octets-concatenated-xsubseqs-to-string (seq) (let ((result (make-array (concatenated-xsubseqs-len seq) :element-type 'character))) (declare (type simple-string result)) (loop with current-pos = 0 for seq in (concatenated-xsubseqs-children seq) do (do ((i (xsubseq-start seq) (1+ i)) (j current-pos (1+ j))) ((= i (xsubseq-end seq)) (setf current-pos j)) (setf (aref result j) (code-char (the (unsigned-byte 8) (aref (the octets (xsubseq-data seq)) i)))))) result)) (defun string-concatenated-xsubseqs-to-sequence (seq) (let ((result (make-string (concatenated-xsubseqs-len seq)))) (declare (type simple-string result)) (loop with current-pos of-type integer = 0 for seq in (concatenated-xsubseqs-children seq) do (replace result (the simple-string (xsubseq-data seq)) :start1 current-pos :start2 (xsubseq-start seq) :end2 (xsubseq-end seq)) (incf current-pos (xsubseq-len seq))) result)) (defmacro with-xsubseqs ((xsubseqs &key initial-value) &body body) `(let ((,xsubseqs ,(or initial-value `(make-null-concatenated-xsubseqs)))) ,@body (typecase ,xsubseqs (null-concatenated-xsubseqs nil) (xsubseq (xsubseq-to-sequence ,xsubseqs)) (t (concatenated-xsubseqs-to-sequence ,xsubseqs)))))
12,008
Common Lisp
.lisp
262
32.820611
109
0.555508
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
1361c14f12b8b777dac2ad8d0d7dec44496d60cac085fe432681aacb5422accd
42,887
[ 345307, 401612 ]
42,888
benchmark.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/xsubseq-20170830-git/t/benchmark.lisp
(in-package :cl-user) (defpackage xsubseq-test.benchmark (:use :cl :xsubseq) (:export :run-benchmark)) (in-package :xsubseq-test.benchmark) (defun run-benchmark () (declare (optimize (speed 3) (safety 0))) (time (let ((result (xsubseq (the (simple-array (unsigned-byte 8) (*)) (make-array 0 :element-type '(unsigned-byte 8))) 0))) (dotimes (i 100000) (xnconcf result (xsubseq (the (simple-array (unsigned-byte 8) (100)) (make-array 100 :element-type '(unsigned-byte 8))) 10 30))))))
652
Common Lisp
.lisp
18
25.833333
80
0.529226
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
d562dee047db238cacd874882f1c7fc0bc692b09d2fa2b099b56db2903d2b01d
42,888
[ 137046 ]
42,889
xsubseq.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/xsubseq-20170830-git/t/xsubseq.lisp
(in-package :cl-user) (defpackage xsubseq-test (:use :cl :xsubseq :prove)) (in-package :xsubseq-test) (plan nil) (defparameter *data1* (make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(1 2 3))) (defparameter *data2* (make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(11 22 33))) (defparameter *str1* "Hello") (defparameter *str2* "World") (subtest "xsubseq" (is-type (xsubseq *data1* 0 1) 'xsubseq "Can create a new XSUBSEQ") (is-type (xsubseq *data1* 0) 'xsubseq "Can omit END") (is-type (xsubseq *str1* 0 1) 'xsubseq "Can create a new XSUBSEQ (string)") (is-type (xsubseq *str2* 0) 'xsubseq "Can omit END (string)")) (subtest "xnconc" (is-type (xnconc (xsubseq *data1* 0 1)) 'xsubseq "1 XSUBSEQ") (is-type (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2)) 'concatenated-xsubseqs "2 XSUBSEQs") (is-type (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2) (xsubseq *data1* 1)) 'concatenated-xsubseqs "3 XSUBSEQs") (is-type (xnconc (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2)) (xsubseq *data1* 1)) 'concatenated-xsubseqs "Concat a CONCATENATED-XSUBSEQS and a XSUBSEQ") (is-type (xnconc (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2)) (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2))) 'concatenated-xsubseqs "Concat 2 CONCATENATED-XSUBSEQSs")) (subtest "coerce-to-sequence" (is (coerce-to-sequence (xsubseq *data1* 0 2)) #(1 2) :test #'equalp "XSUBSEQ") (is (coerce-to-sequence (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2) (xsubseq *data1* 1))) #(1 33 2 3) :test #'equalp "CONCATENATED-XSUBSEQ") (is (coerce-to-sequence (xsubseq *str1* 0 2)) "He" :test #'equal "XSUBSEQ (string)") (is (coerce-to-sequence (xnconc (xsubseq *str1* 0 1) (xsubseq *str2* 2) (xsubseq *str1* 1))) "Hrldello" :test #'equal "CONCATENATED-XSUBSEQ (string)")) (subtest "coerce-to-string" (is (coerce-to-string (xnconc (xsubseq *data2* 2) (xsubseq *data2* 2))) "!!" :test #'equal) (is (coerce-to-string (xnconc (xsubseq *str1* 0 1) (xsubseq *str2* 2))) "Hrld" :test #'equal)) (subtest "xlength" (is (xlength (xsubseq *data1* 0 1)) 1) (is (xlength (xsubseq *data1* 2)) 1) (is (xlength (xnconc (xsubseq *data1* 0 1) (xsubseq *data2* 2))) 2)) (subtest "with-xsubseqs" (is (with-xsubseqs (result) (xnconcf result (xsubseq *data1* 0 1)) (xnconcf result (xsubseq *data2* 2)) (xnconcf result (xsubseq *data1* 1))) #(1 33 2 3) :test #'equalp) (is (with-xsubseqs (result :initial-value (xsubseq *data1* 0)) (xnconcf result (xsubseq *data2* 2)) (xnconcf result (xsubseq *data1* 1))) #(1 2 3 33 2 3) :test #'equalp)) (finalize)
3,326
Common Lisp
.lisp
95
25.684211
80
0.535548
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
4eea9fbed0615f3f5f37005f3ad7ee3cec99308138df8e22dbf88da447fb64b3
42,889
[ 250539 ]
42,891
util.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/util.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/util.lisp,v 1.12 2008/05/25 10:53:48 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :chunga) #-:lispworks (defmacro when-let ((var expr) &body body) "Evaluates EXPR, binds it to VAR, and executes BODY if VAR has a true value." `(let ((,var ,expr)) (when ,var ,@body))) (defun ends-with-p (seq suffix &key (test #'char-equal)) "Returns true if the sequence SEQ ends with the sequence SUFFIX. Individual elements are compared with TEST." (let ((mismatch (mismatch seq suffix :from-end t :test test))) (or (null mismatch) (= mismatch (- (length seq) (length suffix)))))) (defun make-keyword (string destructivep) "Converts the string STRING to a keyword where all characters are uppercase or lowercase, taking into account the current readtable case. Destructively modifies STRING if DESTRUCTIVEP is true." (intern (funcall (if destructivep (if (eq (readtable-case *readtable*) :upcase) #'nstring-upcase #'nstring-downcase) (if (eq (readtable-case *readtable*) :upcase) #'string-upcase #'string-downcase)) string) :keyword)) (defun read-char* (stream &optional (eof-error-p t) eof-value) "The streams we're dealing with are all binary with element type \(UNSIGNED-BYTE 8) and we're only interested in ISO-8859-1, so we use this to `simulate' READ-CHAR." (cond (*char-buffer* (prog1 *char-buffer* (setq *char-buffer* nil))) (t ;; this assumes that character codes are identical to Unicode code ;; points, at least for Latin1 (let ((char-code (read-byte stream eof-error-p eof-value))) (and char-code (code-char char-code)))))) (defun unread-char* (char) "Were simulating UNREAD-CHAR by putting the character into *CHAR-BUFFER*." ;; no error checking, only used internally (setq *char-buffer* char) nil) (defun peek-char* (stream &optional eof-error-p eof-value) "We're simulating PEEK-CHAR by reading a character and putting it into *CHAR-BUFFER*." ;; no error checking, only used internally (setq *char-buffer* (read-char* stream eof-error-p eof-value))) (defmacro with-character-stream-semantics (&body body) "Binds *CHAR-BUFFER* around BODY so that within BODY we can use READ-CHAR* and friends \(see above) to simulate a character stream although we're reading from a binary stream." `(let ((*char-buffer* nil)) ,@body))
3,929
Common Lisp
.lisp
80
44.7
84
0.703704
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
c337378c8239959f7656f846a8c43ca71daa3e53cf38a6ddc44e0953b1d95496
42,891
[ 108672, 189407 ]
42,893
specials.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/specials.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/specials.lisp,v 1.12 2008/05/24 03:06:22 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :chunga) (defmacro define-constant (name value &optional doc) "A version of DEFCONSTANT for, cough, /strict/ CL implementations." ;; See <http://www.sbcl.org/manual/Defining-Constants.html> `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value) ,@(when doc (list doc)))) #+(and :lispworks :lw-editor) (editor:setup-indent "define-constant" 1 2 4) (defconstant +output-buffer-size+ 8192 "Size of the initial output buffer for chunked output.") (define-constant +crlf+ (make-array 2 :element-type '(unsigned-byte 8) :initial-contents (mapcar 'char-code '(#\Return #\Linefeed))) "A 2-element array consisting of the character codes for a CRLF sequence.") (define-constant +hex-digits+ '#.(coerce "0123456789ABCDEF" 'list) "The hexadecimal digits.") (defvar *current-error-message* nil "Used by the parsing functions in `read.lisp' as an introduction to a standardized error message about unexpected characters unless it is NIL.") (defvar *current-error-function* nil "Used by the functions in `read.lisp' as a function to signal errors about unexpected characters when *CURRENT-ERROR-MESSAGE* is NIL.") (defvar *accept-bogus-eols* nil "Some web servers do not respond with a correct CRLF line ending for HTTP headers but with a lone linefeed or carriage return instead. If this variable is bound to a true value, READ-LINE* will treat a lone LF or CR character as an acceptable end of line. The initial value is NIL.") (defvar *treat-semicolon-as-continuation* nil "According to John Foderaro, Netscape v3 web servers bogusly split Set-Cookie headers over multiple lines which means that we'd have to treat Set-Cookie headers ending with a semicolon as incomplete and combine them with the next header. This will only be done if this variable has a true value, though.") (defvar *char-buffer* nil "A `buffer' for one character. Used by PEEK-CHAR* and UNREAD-CHAR*.") (pushnew :chunga *features*) ;; stuff for Nikodemus Siivola's HYPERDOC ;; see <http://common-lisp.net/project/hyperdoc/> ;; and <http://www.cliki.net/hyperdoc> ;; also used by LW-ADD-ONS (defvar *hyperdoc-base-uri* "http://weitz.de/chunga/") (let ((exported-symbols-alist (loop for symbol being the external-symbols of :chunga collect (cons symbol (concatenate 'string "#" (string-downcase symbol)))))) (defun hyperdoc-lookup (symbol type) (declare (ignore type)) (cdr (assoc symbol exported-symbols-alist :test #'eq))))
4,157
Common Lisp
.lisp
80
48.0625
88
0.723934
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
373abe8de9e226059124e0539d3747eabe3932a22256686d9bc80c75d6c89e09
42,893
[ -1 ]
42,894
read.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/read.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/read.lisp,v 1.22 2008/05/26 08:18:00 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :chunga) (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, despite 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)) (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." (<= 0 (char-code char) 127)) (defun controlp (char) "Returns true if the Lisp character CHAR is a CTL according to RFC 2616." (or (<= 0 (char-code char) 31) (= (char-code char) 127))) (defun separatorp (char) "Returns true if the Lisp character CHAR is a separator according to RFC 2616." (find char #.(format nil " ()<>@,;:\\\"/[]?={}~C" #\Tab) :test #'char=)) (defun whitespacep (char) "Returns true if the Lisp character CHAR is whitespace according to RFC 2616." (member char '(#\Space #\Tab) :test #'char=)) (defun token-char-p (char) "Returns true if the Lisp character CHAR is a token constituent according to RFC 2616." (and (charp char) (not (or (controlp char) (separatorp char))))) (defun assert-char (stream expected-char) "Reads the next character from STREAM and checks if it is the character EXPECTED-CHAR. Signals an error otherwise." (let ((char (read-char* stream))) (unless (char= char expected-char) (signal-unexpected-chars stream char expected-char)) char)) (defun assert-crlf (stream) "Reads the next two characters from STREAM and checks if these are a carriage return and a linefeed. Signals an error otherwise." (assert-char stream #\Return) (assert-char stream #\Linefeed)) (defun read-line* (stream &optional log-stream) "Reads and assembles characters from the binary stream STREAM until a carriage return is read. Makes sure that the following character is a linefeed. If *ACCEPT-BOGUS-EOLS* is not NIL, then the function will also accept a lone carriage return or linefeed as an acceptable line break. Returns the string of characters read excluding the line break. Returns NIL if input ends before one character was read. Additionally logs this string to LOG-STREAM if it is not NIL." (let ((result (with-output-to-string (line) (loop for char-seen-p = nil then t for char = (read-char* stream nil) for is-cr-p = (and char (char= char #\Return)) until (or (null char) is-cr-p (and *accept-bogus-eols* (char= char #\Linefeed))) do (write-char char line) finally (cond ((and (not char-seen-p) (null char)) (return-from read-line* nil)) ((not *accept-bogus-eols*) (assert-char stream #\Linefeed)) (is-cr-p (when (eql (peek-char* stream) #\Linefeed) (read-char* stream)))))))) (when log-stream (write-line result log-stream) (finish-output log-stream)) result)) (defun trim-whitespace (string &key (start 0) (end (length string))) "Returns a version of the string STRING \(between START and END) where spaces and tab characters are trimmed from the start and the end. Might return STRING." ;; optimized version to replace STRING-TRIM, suggested by Jason Kantz (declare (optimize speed (space 0) (debug 1) (compilation-speed 0) #+:lispworks (hcl:fixnum-safety 0))) (declare (string string)) (let* ((start% (loop for i of-type fixnum from start below end while (or (char= #\space (char string i)) (char= #\tab (char string i))) finally (return i))) (end% (loop for i of-type fixnum downfrom (1- end) to start while (or (char= #\space (char string i)) (char= #\tab (char string i))) finally (return (1+ i))))) (declare (fixnum start% end%)) (cond ((and (zerop start%) (= end% (length string))) string) ((> start% end%) "") (t (subseq string start% end%))))) (defun read-http-headers (stream &optional log-stream) "Reads HTTP header lines from STREAM \(except for the initial status line which is supposed to be read already) and returns a corresponding alist of names and values where the names are keywords and the values are strings. Multiple lines with the same name are combined into one value, the individual values separated by commas. Header lines which are spread across multiple lines are recognized and treated correctly. Additonally logs the header lines to LOG-STREAM if it is not NIL." (let (headers (*current-error-message* "While reading HTTP headers:")) (labels ((read-header-line () "Reads one header line, considering continuations." (with-output-to-string (header-line) (loop (let ((line (trim-whitespace (read-line* stream log-stream)))) (when (zerop (length line)) (return)) (write-sequence line header-line) (let ((next (peek-char* stream))) (unless (whitespacep next) (return))) ;; we've seen whitespace starting a continutation, ;; so we loop (write-char #\Space header-line))))) (split-header (line) "Splits line at colon and converts it into a cons. Returns NIL if LINE consists solely of whitespace." (unless (zerop (length (trim-whitespace line))) (let ((colon-pos (or (position #\: line :test #'char=) (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) "Adds the name/value cons PAIR to HEADERS. Takes care of multiple headers with the same name." (let* ((name (car pair)) (existing-header (assoc name headers :test #'eq)) (existing-value (cdr existing-header))) (cond (existing-header (setf (cdr existing-header) (format nil "~A~:[,~;~]~A" existing-value (and *treat-semicolon-as-continuation* (eq name :set-cookie) (ends-with-p (trim-whitespace existing-value) ";")) (cdr pair)))) (t (push pair headers)))))) (loop for header-pair = (split-header (read-header-line)) while header-pair do (add-header header-pair))) (nreverse headers))) (defun skip-whitespace (stream) "Consume characters from STREAM until an END-OF-FILE is encountered or a non-whitespace \(according to RFC 2616) characters is seen. This character is returned \(or NIL in case of END-OF-FILE)." (loop for char = (peek-char* stream nil) while (and char (whitespacep char)) do (read-char* stream) finally (return char))) (defun read-token (stream) "Read characters from STREAM while they are token constituents \(according to RFC 2616). It is assumed that there's a token character at the current position. The token read is returned as a string. Doesn't signal an error \(but simply stops reading) if END-OF-FILE is encountered after the first character." (with-output-to-string (out) (loop for first = t then nil for char = (if first (peek-char* stream) (or (peek-char* stream nil) (return))) while (token-char-p char) do (write-char (read-char* stream) out)))) (defun read-quoted-string (stream) "Reads a quoted string \(according to RFC 2616). It is assumed that the character at the current position is the opening quote character. Returns the string read without quotes and escape characters." (read-char* stream) (with-output-to-string (out) (loop for char = (read-char* stream) until (char= char #\") do (case char (#\\ (write-char (read-char* stream) out)) (#\Return (assert-char stream #\Linefeed) (let ((char (read-char* stream))) (unless (whitespacep char) (signal-unexpected-chars stream char '(#\Space #\Tab))))) (otherwise (write-char char out)))))) (defun read-cookie-value (stream &key (separators ";")) "Reads a cookie parameter value from STREAM which is returned as a string. Simply reads until a semicolon is seen \(or an element of SEPARATORS). Also reads quoted strings if the first non-whitespace character is a quotation mark \(as in RFC 2109)." (if (char= #\" (peek-char* stream)) (read-quoted-string stream) (trim-whitespace (with-output-to-string (out) (loop for char = (peek-char* stream nil) until (or (null char) (find char separators :test #'char=)) do (write-char (read-char* stream) out)))))) (defun read-name-value-pair (stream &key (value-required-p t) cookie-syntax) "Reads a typical \(in RFC 2616) name/value or attribute/value combination from STREAM - a token followed by a #\\= character and another token or a quoted string. Returns a cons of name and value, both as strings. If VALUE-REQUIRED-P is NIL, the #\\= sign and the value are optional. If COOKIE-SYNTAX is true, uses READ-COOKIE-VALUE internally." (skip-whitespace stream) (let ((name (if cookie-syntax (read-cookie-value stream :separators "=;") (read-token stream)))) (skip-whitespace stream) (cons name (when (or value-required-p (eql (peek-char* stream nil) #\=)) (assert-char stream #\=) (skip-whitespace stream) (cond (cookie-syntax (read-cookie-value stream)) ((char= (peek-char* stream) #\") (read-quoted-string stream)) (t (read-token stream))))))) (defun read-name-value-pairs (stream &key (value-required-p t) cookie-syntax) "Uses READ-NAME-VALUE-PAIR to read and return an alist of name/value pairs from STREAM. It is assumed that the pairs are separated by semicolons and that the first char read \(except for whitespace) will be a semicolon. The parameters are used as in READ-NAME-VALUE-PAIR. Stops reading in case of END-OF-FILE \(instead of signaling an error)." (loop for char = (skip-whitespace stream) while (and char (char= char #\;)) do (read-char* stream) ;; guard against a stray semicolon at the end when (skip-whitespace stream) collect (read-name-value-pair stream :value-required-p value-required-p :cookie-syntax cookie-syntax)))
13,766
Common Lisp
.lisp
270
40.488889
101
0.607808
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
a6c966c7f3e4db8ed362a5f5673df616307565a8a857f51a69242fe554cdfcff
42,894
[ 268914 ]
42,896
input.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/input.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/input.lisp,v 1.18 2008/05/24 03:06:22 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :chunga) (defmethod chunked-input-stream-extensions ((object t)) "The default method which always returns the empty list." nil) (defmethod chunked-input-stream-trailers ((object t)) "The default method which always returns the empty list." nil) (defmethod chunked-stream-input-chunking-p ((object t)) "The default method for all objects which are not of type CHUNKED-INPUT-STREAM." nil) (defmethod (setf chunked-stream-input-chunking-p) (new-value (stream chunked-input-stream)) "Switches input chunking for STREAM on or off." (unless (eq (not new-value) (not (chunked-stream-input-chunking-p stream))) (with-slots (input-limit input-index expecting-crlf-p chunk-extensions chunk-trailers) stream (cond (new-value (setq expecting-crlf-p nil input-limit 0 input-index 0 chunk-extensions nil chunk-trailers nil)) (t (when (< input-index input-limit) (error 'parameter-error :stream stream :format-control "Not all chunks from ~S have been read completely." :format-arguments (list stream))))))) (setf (slot-value stream 'input-chunking-p) new-value)) (defmethod stream-clear-input ((stream chunked-input-stream)) "Implements CLEAR-INPUT by resetting the internal chunk buffer." (when (chunked-stream-input-chunking-p stream) (setf (chunked-stream-input-index stream) 0 (chunked-stream-input-limit stream) 0)) ;; clear input on inner stream (clear-input (chunked-stream-stream stream)) nil) (defmethod chunked-input-available-p ((stream chunked-input-stream)) "Whether there's unread input waiting in the chunk buffer." (< (chunked-stream-input-index stream) (chunked-stream-input-limit stream))) (defmethod stream-listen ((stream chunked-input-stream)) "We first check if input chunking is enabled and if there's something in the buffer. Otherwise we poll the underlying stream." (cond ((chunked-stream-input-chunking-p stream) (or (chunked-input-available-p stream) (fill-buffer stream))) ((eq (chunked-input-stream-eof-after-last-chunk stream) :eof) nil) (t (listen (chunked-stream-stream stream))))) (defmethod fill-buffer ((stream chunked-input-stream)) "Re-fills the chunk buffer. Returns NIL if chunking has ended." (let ((inner-stream (chunked-stream-stream stream)) ;; set up error function for the functions in `read.lisp' (*current-error-function* (lambda (last-char expected-chars) "The function which is called when an unexpected character is seen. Signals INPUT-CHUNKING-BODY-CORRUPTED." (error 'input-chunking-body-corrupted :stream stream :last-char last-char :expected-chars expected-chars)))) (labels ((add-extensions () "Reads chunk extensions \(if there are any) and stores them into the corresponding slot of the stream." (when-let (extensions (read-name-value-pairs inner-stream)) (warn 'chunga-warning :stream stream :format-control "Adding uninterpreted extensions to stream ~S." :format-arguments (list stream)) (setf (slot-value stream 'chunk-extensions) (append (chunked-input-stream-extensions stream) extensions))) (assert-crlf inner-stream)) (get-chunk-size () "Reads chunk size header \(including optional extensions) and returns the size." (with-character-stream-semantics (when (expecting-crlf-p stream) (assert-crlf inner-stream)) (setf (expecting-crlf-p stream) t) ;; read hexadecimal number (let (last-char) (prog1 (loop for weight = (digit-char-p (setq last-char (read-char* inner-stream)) 16) for result = (if weight (+ weight (* 16 (or result 0))) (return (or result (error 'input-chunking-body-corrupted :stream stream :last-char last-char :expected-chars +hex-digits+))))) ;; unread first octet which wasn't a digit (unread-char* last-char) (add-extensions)))))) (let ((chunk-size (get-chunk-size))) (with-slots (input-buffer input-limit input-index) stream (setq input-index 0 input-limit chunk-size) (cond ((zerop chunk-size) ;; turn chunking off (setf (chunked-stream-input-chunking-p stream) nil (slot-value stream 'chunk-trailers) (with-character-stream-semantics (read-http-headers inner-stream)) input-limit 0) (when (chunked-input-stream-eof-after-last-chunk stream) (setf (chunked-input-stream-eof-after-last-chunk stream) :eof)) ;; return NIL (return-from fill-buffer)) ((> chunk-size (length input-buffer)) ;; replace buffer if it isn't big enough for the next chunk (setq input-buffer (make-array chunk-size :element-type '(unsigned-byte 8))))) (unless (= (read-sequence input-buffer inner-stream :start 0 :end chunk-size) chunk-size) (error 'input-chunking-unexpected-end-of-file :stream stream)) chunk-size))))) (defmethod stream-read-byte ((stream chunked-input-stream)) "Reads one byte from STREAM. Checks the chunk buffer first, if input chunking is enabled. Re-fills buffer is necessary." (unless (chunked-stream-input-chunking-p stream) (return-from stream-read-byte (if (eq (chunked-input-stream-eof-after-last-chunk stream) :eof) :eof (read-byte (chunked-stream-stream stream) nil :eof)))) (unless (chunked-input-available-p stream) (unless (fill-buffer stream) (return-from stream-read-byte :eof))) (with-slots (input-buffer input-index) stream (prog1 (aref input-buffer input-index) (incf input-index)))) (defmethod stream-read-sequence ((stream chunked-input-stream) sequence start end &key) "Fills SEQUENCE by adding data from the chunk buffer and re-filling it until enough data was read. Works directly on the underlying stream if input chunking is off." (unless (chunked-stream-input-chunking-p stream) (return-from stream-read-sequence (if (eq (chunked-input-stream-eof-after-last-chunk stream) :eof) 0 (read-sequence sequence (chunked-stream-stream stream) :start start :end end)))) (loop (when (>= start end) (return-from stream-read-sequence start)) (unless (chunked-input-available-p stream) (unless (fill-buffer stream) (return-from stream-read-sequence start))) (with-slots (input-buffer input-limit input-index) stream (replace sequence input-buffer :start1 start :end1 end :start2 input-index :end2 input-limit) (let ((length (min (- input-limit input-index) (- end start)))) (incf start length) (incf input-index length)))))
9,402
Common Lisp
.lisp
178
41.275281
101
0.617507
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
2ddc64686052869a492ba297971d0a90926ad9f494d67aa5943e3adc7404dd85
42,896
[ 403904 ]
42,897
streams.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/streams.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CHUNGA; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/streams.lisp,v 1.10 2008/05/24 03:06:22 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :chunga) (defclass chunked-stream (trivial-gray-stream-mixin) ((real-stream :initarg :real-stream :reader chunked-stream-stream :documentation "The actual stream that's used for input and/or output.")) (:documentation "Every chunked stream returned by MAKE-CHUNKED-STREAM is of this type which is a subtype of STREAM.")) (defclass chunked-input-stream (chunked-stream fundamental-binary-input-stream) ((input-chunking-p :initform nil :reader chunked-stream-input-chunking-p :documentation "Whether input chunking is currently enabled.") (input-buffer :initform nil :documentation "A vector containing the binary data from the most recent chunk that was read.") (input-index :initform 0 :accessor chunked-stream-input-index :documentation "The current position within INPUT-BUFFER.") (input-limit :initform 0 :accessor chunked-stream-input-limit :documentation "Only the content in INPUT-BUFFER up to INPUT-LIMIT belongs to the current chunk.") (chunk-extensions :initform nil :reader chunked-input-stream-extensions :documentation "An alist of attribute/value pairs corresponding to the optional `chunk extensions' which might be encountered when reading from a chunked stream.") (chunk-trailers :initform nil :reader chunked-input-stream-trailers :documentation "An alist of attribute/value pairs corresponding to the optional `trailer' HTTP headers which might be encountered at the end of a chunked stream.") (expecting-crlf-p :initform nil :accessor expecting-crlf-p :documentation "Whether we expect to see CRLF before we can read the next chunk-size header part from the stream. \(This will actually be the CRLF from the end of the last chunk-data part.)") (signal-eof :initform nil :accessor chunked-input-stream-eof-after-last-chunk :documentation "Return EOF after the last chunk instead of simply switching chunking off.")) (:documentation "A chunked stream is of this type if its underlying stream is an input stream. This is a subtype of CHUNKED-STREAM.")) (defclass chunked-output-stream (chunked-stream fundamental-binary-output-stream) ((output-chunking-p :initform nil :reader chunked-stream-output-chunking-p :documentation "Whether output chunking is currently enabled.") (output-buffer :initform (make-array +output-buffer-size+ :element-type '(unsigned-byte 8)) :accessor output-buffer :documentation "A vector used to temporarily store data which will output in one chunk.") (output-index :initform 0 :accessor output-index :documentation "The current end of OUTPUT-BUFFER.")) (:documentation "A chunked stream is of this type if its underlying stream is an output stream. This is a subtype of CHUNKED-STREAM.")) (defclass chunked-io-stream (chunked-input-stream chunked-output-stream) () (:documentation "A chunked stream is of this type if it is both a CHUNKED-INPUT-STREAM as well as a CHUNKED-OUTPUT-STREAM.")) (defmethod stream-element-type ((stream chunked-stream)) "Chunked streams are always binary streams. Wrap them with flexi streams if you need a character stream." '(unsigned-byte 8)) (defmethod open-stream-p ((stream chunked-stream)) "A chunked stream is open if its underlying stream is open." (open-stream-p (chunked-stream-stream stream))) (defmethod close ((stream chunked-stream) &key abort) "If a chunked stream is closed, we close the underlying stream as well." (with-slots (real-stream) stream (cond ((open-stream-p real-stream) (close real-stream :abort abort)) (t nil)))) (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 '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)) 'chunked-io-stream) ((input-stream-p stream) 'chunked-input-stream) ((output-stream-p stream) 'chunked-output-stream)) :real-stream stream))
6,302
Common Lisp
.lisp
121
44.801653
94
0.691909
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
5792469abe231f2b97ab9cc94ed07c6df2ac7e0d10b735f824e96863f014d8a8
42,897
[ 165957 ]
42,898
packages.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/chunga-20221106-git/packages.lisp
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-USER; Base: 10 -*- ;;; $Header: /usr/local/cvsrep/chunga/packages.lisp,v 1.19 2008/05/24 18:38:30 edi Exp $ ;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved. ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; * Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; * Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials ;;; provided with the distribution. ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (in-package :cl-user) (defpackage :chunga (:use :cl :trivial-gray-streams) #+:lispworks (:import-from :lw :when-let) (:export :*accept-bogus-eols* :*current-error-message* :*treat-semicolon-as-continuation* :assert-char :as-keyword :as-capitalized-string :chunga-error :chunga-warning :chunked-input-stream :chunked-input-stream-extensions :chunked-input-stream-trailers :chunked-io-stream :chunked-output-stream :chunked-stream :chunked-stream-input-chunking-p :chunked-stream-output-chunking-p :chunked-stream-stream :input-chunking-body-corrupted :input-chunking-unexpected-end-of-file :make-chunked-stream :read-http-headers :peek-char* :read-char* :read-line* :read-name-value-pair :read-name-value-pairs :read-token :skip-whitespace :syntax-error :token-char-p :trim-whitespace :with-character-stream-semantics :chunked-input-stream-eof-after-last-chunk))
2,751
Common Lisp
.lisp
61
37.885246
88
0.67091
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
46d981ceeb4aa2362855dcd8865489e3d4fce3cc41f87f34fe5d2a5248a2da12
42,898
[ 182797 ]
42,899
util.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/fast-http-20191007-git/src/util.lisp
(in-package :cl-user) (defpackage fast-http.util (:use :cl) (:import-from :fast-http.error :strict-error) (:import-from :alexandria :once-only :ensure-list) (:import-from :cl-utilities :with-collectors) (:export :defun-insane :defun-speedy :defun-careful :casev :casev= :case-byte :tagcase :tagcasev :tagcasev= :make-collector :number-string-p)) (in-package :fast-http.util) (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *insane-declaration* '(declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)))) (defvar *speedy-declaration* '(declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)))) (defvar *careful-declaration* '(declare (optimize (speed 3) (safety 2))))) (defmacro defun-insane (name lambda-list &body body) `(progn (declaim (inline ,name)) (defun ,name ,lambda-list ,*insane-declaration* ,@body))) (defmacro defun-speedy (name lambda-list &body body) `(progn (declaim (notinline ,name)) (defun ,name ,lambda-list ,*speedy-declaration* ,@body))) (defmacro defun-careful (name lambda-list &body body) `(progn (declaim (notinline ,name)) (defun ,name ,lambda-list ,*careful-declaration* ,@body))) (defmacro casev (keyform &body clauses) (once-only (keyform) (flet ((get-val (val) (cond ((eq val 'otherwise) val) ((symbolp val) (symbol-value val)) ((constantp val) val) (T (error "CASEV can be used only with variables or constants"))))) `(case ,keyform ,@(loop for (val . clause) in clauses if (eq val 'otherwise) collect `(otherwise ,@clause) else if (listp val) collect `((,@(mapcar #'get-val val)) ,@clause) else collect `(,(get-val val) ,@clause)))))) (defmacro casev= (keyform &body clauses) (once-only (keyform) (flet ((get-val (val) (cond ((eq val 'otherwise) val) ((symbolp val) (symbol-value val)) ((constantp val) val) (T (error "CASEV can be used only with variables or constants"))))) `(cond ,@(loop for (val . clause) in clauses if (eq val 'otherwise) collect `(T ,@clause) else if (listp val) collect `((or ,@(mapcar (lambda (val) `(= ,keyform ,(get-val val))) val)) ,@clause) else collect `((= ,keyform ,(get-val val)) ,@clause)))))) (defmacro case-byte (byte &body cases) `(casev= ,byte ,@(loop for (val . form) in cases if (eq val 'otherwise) collect `(,val ,@form) else if (listp val) collect `(,(mapcar #'char-code val) ,@form) else collect `(,(char-code val) ,@form)))) (defmacro tagcase (keyform &body blocks) (let ((end (gensym "END"))) `(tagbody (case ,keyform ,@(loop for (tag . body) in blocks if (eq tag 'otherwise) collect `(otherwise ,@body (go ,end)) else collect `(,tag (go ,(if (listp tag) (car tag) tag))))) (go ,end) ,@(loop for (tag . body) in blocks if (listp tag) append tag else collect tag collect `(progn ,@body (go ,end))) ,end))) (defmacro tagcasev (keyform &body blocks) (let ((end (gensym "END"))) `(tagbody (casev ,keyform ,@(loop for (tag . body) in blocks if (eq tag 'otherwise) collect `(otherwise ,@body (go ,end)) else collect `(,tag (go ,(if (listp tag) (car tag) tag))))) (go ,end) ,@(loop for (tag . body) in blocks if (listp tag) append tag else if (not (eq tag 'otherwise)) collect tag collect `(progn ,@body (go ,end))) ,end))) (defmacro tagcasev= (keyform &body blocks) (let ((end (gensym "END"))) `(tagbody (casev= ,keyform ,@(loop for (tag . body) in blocks if (eq tag 'otherwise) collect `(otherwise ,@body (go ,end)) else collect `(,tag (go ,(if (listp tag) (car tag) tag))))) (go ,end) ,@(loop for (tag . body) in blocks if (listp tag) append tag else if (not (eq tag 'otherwise)) collect tag collect `(progn ,@body (go ,end))) ,end))) (defun make-collector () (let ((none '#:none)) (declare (dynamic-extent none)) (with-collectors (buffer) (return-from make-collector (lambda (&optional (data none)) (unless (eq data none) (buffer data)) buffer))))) (declaim (inline %whitespacep)) (defun %whitespacep (char) (declare (type character char) (optimize (speed 3) (safety 0))) (or (char= char #\Space) (char= char #\Tab))) (declaim (inline position-not-whitespace)) (defun position-not-whitespace (string &key from-end) (declare (type #+ecl string #-ecl simple-string string) (optimize (speed 3) (safety 0))) (let* ((len (length string)) (start (if from-end (1- len) 0)) (end (if from-end 0 (1- len))) (step-fn (if from-end #'1- #'1+))) (declare (type integer len start end)) (do ((i start (funcall step-fn i))) ((= i end) i) (declare (type integer i)) (unless (%whitespacep (aref string i)) (return-from position-not-whitespace i))))) (declaim (inline number-string-p)) (defun number-string-p (string) (declare (type #+ecl string #-ecl simple-string string) (optimize (speed 3) (safety 2))) ;; empty string (when (zerop (length string)) (return-from number-string-p nil)) (let ((end (position-not-whitespace string :from-end t)) (dot-read-p nil)) ;; spaces string (when (null end) (return-from number-string-p nil)) (locally (declare (type integer end) (optimize (safety 0))) (incf end) (do ((i (the integer (or (position-not-whitespace string) 0)) (1+ i))) ((= i end) T) (declare (type integer i)) (let ((char (aref string i))) (declare (type character char)) (cond ((alpha-char-p char) (return-from number-string-p nil)) ((digit-char-p char)) ((char= char #\.) (when dot-read-p (return-from number-string-p nil)) (setq dot-read-p t)) (T (return-from number-string-p nil))))))))
7,321
Common Lisp
.lisp
200
25.485
106
0.505417
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
7bf895768912ad284bc143ba986e58ab7b3b940580c0e767a89c288770494bfc
42,899
[ 44527 ]
42,900
error.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/fast-http-20191007-git/src/error.lisp
(in-package :cl-user) (defpackage fast-http.error (:use :cl) (:export :fast-http-error :callback-error :cb-message-begin :cb-url :cb-first-line :cb-header-field :cb-header-value :cb-headers-complete :cb-body :cb-message-complete :cb-status :parsing-error :invalid-eof-state :header-overflow :closed-connection :invalid-version :invalid-status :invalid-method :invalid-url :invalid-host :invalid-port :invalid-path :invalid-query-string :invalid-fragment :lf-expected :invalid-header-token :invalid-content-length :invalid-chunk-size :invalid-constant :invalid-internal-state :strict-error :paused-error :unknown-error :multipart-parsing-error :invalid-multipart-body :invalid-boundary :header-value-parsing-error :invalid-header-value :invalid-parameter-key :invalid-parameter-value)) (in-package :fast-http.error) (define-condition fast-http-error (simple-error) (description) (:report (lambda (condition stream) (format stream "~A: ~A" (type-of condition) (slot-value condition 'description))))) ;; ;; Callback-related errors (define-condition callback-error (fast-http-error) ((error :initarg :error :initform nil)) (:report (lambda (condition stream) (with-slots (description error) condition (format stream "Callback Error: ~A~:[~;~:*~% ~A~]" description error))))) (define-condition cb-message-begin (callback-error) ((description :initform "the message-begin callback failed"))) (define-condition cb-url (callback-error) ((description :initform "the url callback failed"))) (define-condition cb-first-line (callback-error) ((description :initform "the first line callback failed"))) (define-condition cb-header-field (callback-error) ((description :initform "the header-field callback failed"))) (define-condition cb-header-value (callback-error) ((description :initform "the header-value callback failed"))) (define-condition cb-headers-complete (callback-error) ((description :initform "the headers-complete callback failed"))) (define-condition cb-body (callback-error) ((description :initform "the body callback failed"))) (define-condition cb-message-complete (callback-error) ((description :initform "the message-complete callback failed"))) (define-condition cb-status (callback-error) ((description :initform "the status callback failed"))) ;; ;; Parsing-related errors (define-condition parsing-error (fast-http-error) ()) (define-condition invalid-eof-state (parsing-error) ((description :initform "stream ended at an unexpected time"))) (define-condition header-overflow (parsing-error) ((description :initform "too many header bytes seen; overflow detected"))) (define-condition closed-connection (parsing-error) ((description :initform "data received after completed connection: close message"))) (define-condition invalid-version (parsing-error) ((description :initform "invalid HTTP version"))) (define-condition invalid-status (parsing-error) ((description :initform "invalid HTTP status code") (status-code :initarg :status-code :initform nil)) (:report (lambda (condition stream) (with-slots (description status-code) condition (format stream "~A: ~A~:[~;~:* (Code=~A)~]" (type-of condition) description status-code))))) (define-condition invalid-method (parsing-error) ((description :initform "invalid HTTP method"))) (define-condition invalid-url (parsing-error) ((description :initform "invalid URL"))) (define-condition invalid-host (parsing-error) ((description :initform "invalid host"))) (define-condition invalid-port (parsing-error) ((description :initform "invalid port"))) (define-condition invalid-path (parsing-error) ((description :initform "invalid path"))) (define-condition invalid-query-string (parsing-error) ((description :initform "invalid query string"))) (define-condition invalid-fragment (parsing-error) ((description :initform "invalid fragment"))) (define-condition lf-expected (parsing-error) ((description :initform "LF character expected"))) (define-condition invalid-header-token (parsing-error) ((description :initform "invalid character in header"))) (define-condition invalid-content-length (parsing-error) ((description :initform "invalid character in content-length header"))) (define-condition invalid-chunk-size (parsing-error) ((description :initform "invalid character in chunk size header"))) (define-condition invalid-constant (parsing-error) ((description :initform "invalid constant string"))) (define-condition invalid-internal-state (parsing-error) ((description :initform "encountered unexpected internal state") (code :initarg :code)) (:report (lambda (condition stream) (format stream "~A: ~A (Code=~A)" (type-of condition) (slot-value condition 'description) (slot-value condition 'code))))) (define-condition strict-error (parsing-error) ((description :initform "strict mode assertion failed") (form :initarg :form)) (:report (lambda (condition stream) (format stream "~A: ~A~% ~A" (type-of condition) (slot-value condition 'description) (slot-value condition 'form))))) (define-condition paused-error (parsing-error) ((description :initform "parser is paused"))) (define-condition unknown-error (parsing-error) ((description :initform "an unknown error occured"))) ;; ;; Multipart parsing (define-condition multipart-parsing-error (fast-http-error) ()) (define-condition invalid-multipart-body (multipart-parsing-error) ((description :initform "invalid multipart body"))) (define-condition invalid-boundary (multipart-parsing-error) ((description :initform "invalid boundary"))) ;; ;; Header value parsing (define-condition header-value-parsing-error (multipart-parsing-error) ()) (define-condition invalid-header-value (header-value-parsing-error) ((description :initform "invalid header value"))) (define-condition invalid-parameter-key (header-value-parsing-error) ((description :initform "invalid parameter key"))) (define-condition invalid-parameter-value (header-value-parsing-error) ((description :initform "invalid parameter value")))
6,769
Common Lisp
.lisp
160
36.0125
88
0.691058
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
467b71937100b173220edcc526c4e4994e778b4f829f8d0f086585fabe2305d1
42,900
[ 324704 ]
42,901
http.lisp
NailykSturm_Info805-TP/src/Import/quicklisp/dists/quicklisp/software/fast-http-20191007-git/src/http.lisp
(in-package :cl-user) (defpackage fast-http.http (:use :cl) (:export :http :http-request :http-response :make-http :make-http-request :make-http-response :http-p :http-request-p :http-response-p :http-major-version :http-minor-version :http-version :http-method :http-status :http-content-length :http-chunked-p :http-upgrade-p :http-headers :http-resource :http-status-text :http-header-read :http-mark :http-state ;; Types :status-code ;; States :+state-first-line+ :+state-headers+ :+state-chunk-size+ :+state-body+ :+state-chunk-body-end-crlf+ :+state-trailing-headers+)) (in-package :fast-http.http) ;; ;; Types (deftype status-code () '(integer 0 10000)) ;; ;; States (defconstant +state-first-line+ 0) (defconstant +state-headers+ 1) (defconstant +state-chunk-size+ 2) (defconstant +state-body+ 3) (defconstant +state-chunk-body-end-crlf+ 4) (defconstant +state-trailing-headers+ 5) (defstruct (http (:conc-name :http-)) (method nil :type symbol) (major-version 0 :type fixnum) (minor-version 9 :type fixnum) (status 0 :type status-code) (content-length nil :type (or null integer)) (chunked-p nil :type boolean) (upgrade-p nil :type boolean) headers ;; private (header-read 0 :type fixnum) (mark -1 :type fixnum) (state +state-first-line+ :type fixnum)) (defun http-version (http) (float (+ (http-major-version http) (/ (http-minor-version http) 10)))) (defstruct (http-request (:include http) (:conc-name :http-)) resource) (defstruct (http-response (:include http) (:conc-name :http-)) status-text)
1,959
Common Lisp
.lisp
70
20.557143
46
0.581644
NailykSturm/Info805-TP
0
0
0
GPL-3.0
9/19/2024, 11:51:23 AM (Europe/Amsterdam)
1c219a602babd346e02bd29696fa0d3baffe43cfbc145c0ec177d53f42c959a0
42,901
[ 61868 ]