You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
Common Lisp
52 lines
1.5 KiB
Common Lisp
;;; util.lisp
|
|
|
|
(in-package :seanut)
|
|
|
|
(declaim (inline seanut-version generate-authorization ensure-scheme
|
|
json-request))
|
|
|
|
(defun maybe-parse-integer (str)
|
|
(or (parse-integer str :junk-allowed t) -1))
|
|
|
|
(defun string-to-keyword (str)
|
|
(intern (string-upcase str) :keyword))
|
|
|
|
(defun validate-media-type (type)
|
|
(car (member type *valid-media-types* :test #'string=)))
|
|
|
|
(defun seanut-version ()
|
|
"gets the system version"
|
|
#.(asdf:component-version (asdf:find-system :seanut)))
|
|
|
|
(defun md5-string (str)
|
|
"returns the MD5 hash of STR"
|
|
(format nil "~{~X~}"
|
|
(coerce (digest-sequence 'ironclad:md5
|
|
(string-to-octets str))
|
|
'list)))
|
|
|
|
(defun generate-authorization (token)
|
|
"generates a properly formatted authorization header"
|
|
(format nil *authorization-format*
|
|
(seanut-version) (uiop:hostname) (md5-string (uiop:hostname))
|
|
(seanut-version) token))
|
|
|
|
(defun format-url (str slug &rest args)
|
|
(format nil "~:[https://~;~]~A/~A"
|
|
(uiop:string-prefix-p "https://" str)
|
|
str (apply #'format `(nil ,slug ,@args))))
|
|
|
|
(defmacro quit-with-message (code message &rest args)
|
|
`(progn
|
|
(format t (concatenate 'string ,message "~&") ,@args)
|
|
(uiop:quit ,code)))
|
|
|
|
(defmacro handle-user-abort (form &rest extra-cases)
|
|
`(handler-case
|
|
(with-user-abort ,form)
|
|
(user-abort () (uiop:quit 0))
|
|
,@extra-cases))
|
|
|
|
(defun json-request (url auth &key (method :get))
|
|
(parse (dex:request url :method method :headers `(("X-Emby-Authorization" . ,auth)))))
|