Extensible handle-message

This commit is contained in:
Mariano Montone 2024-12-18 10:46:31 -03:00
parent 961b87f285
commit 3b27576174

View file

@ -89,11 +89,20 @@
;; handle-message ;; ;; handle-message ;;
;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;
(defvar *message-handlers* '()
"List of message handling functions.
Each entry in the list should be a FUNCTION-DESIGNATOR that will receive
a splitted message and a connection id and should return something
other than NIL iff it handled the message.")
(defun handle-message (connection message) (defun handle-message (connection message)
"Handle incoming websocket MESSAGE on CONNECTION. (Private)" "Handle incoming websocket MESSAGE on CONNECTION. (Private)"
(handler-case (handler-case
(let ((connection-id (gethash connection *connections*)) (let ((connection-id (gethash connection *connections*))
(ml (ppcre:split ":" message :limit 2))) (ml (ppcre:split ":" message :limit 2)))
(dolist (message-handler *message-handlers*)
(when (funcall message-handler ml connection-id)
(return-from handle-message)))
(cond ((null connection-id) (cond ((null connection-id)
;; a zombie connection ;; a zombie connection
(when *verbose-output* (when *verbose-output*