Common Lisp Package: CLACK.UTIL

# Clack.Util - Utilities for Clack core or middleware development. ## DESCRIPTION Most of time, Clack uses other utility libraries (ex. Alexandria), but I realized they were not enough for Clack. See each description of these functions for detail. ## AUTHOR Eitarow Fukamachi (e.arrows@gmail.com)

README:

FUNCTION

Public

APPLY-MIDDLEWARE (APP MW-CLASS-NAME MW-PACKAGE &REST ARGS)

Apply a middleware to the `app'. This function is for resolving symbol packages in run-time.

FIND-HANDLER (SERVER &KEY (FORCE T))

Return a handler package. `server` must be a symbol or a keyword, not containing "Clack.Handler." as a prefix. Example: (find-handler :hunchentoot)

GENERATE-RANDOM-ID

Generate a random token.

LOAD-HANDLER (SERVER)

Load a handler system in run-time. `server` must be a symbol or a keyword. Example: (load-handler :hunchentoot)

MAKE-TMP-FILE-NAME (&OPTIONAL (PREFIX clack))

Generates a unique name for a temporary file.

MERGE-PLIST (P1 P2)

Merge two plist into one plist. If same keys in two plist, second one will be adopted. Example: (merge-plist '(:apple 1 :grape 2) '(:banana 3 :apple 4)) ;;=> (:GRAPE 2 :BANANA 3 :APPLE 4)

NAPPEND (&REST LIST-OF-LIST)

Similar to `nconc` but assures `list` to be rewritten with the result.

Undocumented

HMAC-SHA1-HEX-STRING (STRING SECRET)

HTML-ENCODE (STR)

Private

ASCII-STRING-TO-BYTE-ARRAY (STRING &KEY (START 0) END)

Convert STRING to a (VECTOR (UNSIGNED-BYTE 8)). It is an error if STRING contains any character whose CHAR-CODE is greater than 255.

BYTE-ARRAY-TO-HEX-STRING (VECTOR &KEY (START 0) END (ELEMENT-TYPE 'BASE-CHAR))

Return a string containing the hexadecimal representation of the subsequence of VECTOR between START and END. ELEMENT-TYPE controls the element-type of the returned string.

MAKE-DIGEST (DIGEST-NAME &REST KEYS &KEY &ALLOW-OTHER-KEYS)

Return a digest object which uses the algorithm DIGEST-NAME.

MAKE-KEYWORD (NAME)

Interns the string designated by NAME in the KEYWORD package.

NORMALIZE-KEY (NAME)

key must be a keyword.

REGEX-REPLACE-ALL (REGEX TARGET-STRING REPLACEMENT &KEY (START 0) (END (LENGTH TARGET-STRING)) PRESERVE-CASE SIMPLE-CALLS (ELEMENT-TYPE 'CHARACTER))

Try to match TARGET-STRING between START and END against REGEX and replace all matches with REPLACEMENT. Two values are returned; the modified string, and T if REGEX matched or NIL otherwise. REPLACEMENT can be a string which may contain the special substrings "\&" for the whole match, "\`" for the part of TARGET-STRING before the match, "\'" for the part of TARGET-STRING after the match, "\N" or "\{N}" for the Nth register where N is a positive integer. REPLACEMENT can also be a function designator in which case the match will be replaced with the result of calling the function designated by REPLACEMENT with the arguments TARGET-STRING, START, END, MATCH-START, MATCH-END, REG-STARTS, and REG-ENDS. (REG-STARTS and REG-ENDS are arrays holding the start and end positions of matched registers or NIL - the meaning of the other arguments should be obvious.) Finally, REPLACEMENT can be a list where each element is a string, one of the symbols :MATCH, :BEFORE-MATCH, or :AFTER-MATCH - corresponding to "\&", "\`", and "\'" above -, an integer N - representing register (1+ N) -, or a function designator. If PRESERVE-CASE is true, the replacement will try to preserve the case (all upper case, all lower case, or capitalized) of the match. The result will always be a fresh string, even if REGEX doesn't match. ELEMENT-TYPE is the element type of the resulting string.

Undocumented

HMAC-DIGEST (HMAC &KEY BUFFER (BUFFER-START 0))

MAKE-HMAC (KEY DIGEST-NAME)

UPDATE-HMAC (HMAC SEQUENCE &KEY (START 0) (END (LENGTH SEQUENCE)))

MACRO

Public

GETF* (PLACE KEY)

Similar to `getf' but allows many types for the `key', String, Keyword or Symbol.

NAMESPACE (NAME &REST BODY)

Similar to `defpackage', but the difference is ensure to be in :CL-USER before and to be in the new package after. This may be useful for 'one-package-per-one-file' style.

REMF* (PLACE KEY)

Similar to `remf` but allows many types for the `key', String, Keyword or Symbol.

GENERIC-FUNCTION

Private

DIGEST-SEQUENCE (DIGEST-SPEC SEQUENCE &REST ARGS &KEY START END DIGEST DIGEST-START (DIGEST-START 0) (START 0))

Return the digest of the subsequence of SEQUENCE specified by START and END using the algorithm DIGEST-NAME. For CMUCL and SBCL, SEQUENCE can be any vector with an element-type of (UNSIGNED-BYTE 8); for other implementations, SEQUENCE must be a (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (*)). If DIGEST is provided, the digest will be placed into DIGEST starting at DIGEST-START. DIGEST must be a (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (*)). An error will be signaled if there is insufficient room in DIGEST.

VARIABLE

Public

*TMP-DIRECTORY*

Directory for temporary files created by MAKE-TMP-FILE-NAME.