forked from j4yk/cl-xmpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utility.lisp
61 lines (49 loc) · 2.06 KB
/
utility.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;;; $Id: utility.lisp,v 1.11 2005-11-18 22:29:27 eenge Exp $
;;;; $Source: /project/cl-xmpp/cvsroot/cl-xmpp/utility.lisp,v $
;;;; See the LICENSE file for licensing information.
(in-package :xmpp)
(defmacro fmt (string &rest args)
`(format nil ,string ,@args))
(defun flatten (list)
(cond
((typep list 'atom) list)
((typep (car list) 'atom) (cons (car list)
(flatten (cdr list))))
((typep (car list) 'list) (flatten (append (car list) (cdr list))))))
(defun digestify-string (string)
(ironclad:byte-array-to-hex-string
(ironclad:digest-sequence
:sha1 (ironclad:ascii-string-to-byte-array string))))
(defun make-digest-password (stream-id password)
(string-downcase (digestify-string (fmt "~a~a" stream-id password))))
(defun default-stanza-callback (stanza connection &key dom-repr)
(let ((result (parse-result connection stanza)))
(if dom-repr
(handle connection result)
(handle connection (dom-to-event connection result)))))
(defun list-auth-method-names ()
(mapcar #'car *auth-methods*))
(defun get-auth-method (name)
(let ((auth-method (second (assoc name *auth-methods*))))
(if auth-method
(return-from get-auth-method auth-method)
(error "Unknown mechanism name: ~s. Please choose between: ~s."
name (list-auth-method-names)))))
(defun add-auth-method (name operator)
(push (list name operator) *auth-methods*))
(defun ensure-keyword (thing)
"Makes a keyword except when it gets nil it just returns nil."
(cond
((typep thing 'string)
(let ((correct-case-thing (if (eq *print-case* :upcase)
(string-upcase thing)
(string-downcase thing))))
(intern correct-case-thing :keyword)))
((typep thing 'array) (ensure-keyword (map 'string #'code-char thing)))
((eq thing nil) nil)
(t (error "Don't know how to make keyword out of: ~a (type: ~a)" thing (type-of thing)))))
(defun vector-to-array (vector)
(let ((array (make-array (length vector) :element-type '(unsigned-byte 8))))
(dotimes (position (length vector))
(setf (aref array position) (aref vector position)))
array))