Handle search error gracefully and some cleanup

master
Hugo Thunnissen 6 years ago
parent d3e740ccf3
commit 1de0721ec6

@ -7,14 +7,13 @@
"Connect to a server supporting the STOMP protocol"
(message "Not implemented yet"))
;; TODO: make this send more than just the sommand
;; TODO: make this send more than just the command
(defun stomp-send-message (process message)
"Send a message to a STOMP process"
(process-send-string
process
(format "%s\n\n\u0000\n" (alist-get 'command message))))
;; TODO: debug this and find a fast way to test it
(defun stomp-filter-function (callback)
"Filter function to be used with processes"
(unless (functionp callback) (signal 'wrong-type-argument 'functionp))
@ -36,7 +35,7 @@
(defun stomp-delete-message (buffer)
"Delete the top-most messsage in a buffer"
(with-current-buffer buffer
(delete-region (point-min) (+ 2x (stomp-find-message-end-point buffer)))))
(delete-region (point-min) (+ 2 (stomp-find-message-end-point buffer)))))
(defun stomp-read-message (buffer)
"Attempt to read a single message from a buffer.
@ -47,21 +46,16 @@
(goto-char (point-min))
(while (search-forward "\r" nil t)
(replace-match ""))
(let ((message ()) (headers ()) (content)
(headers-end-point (stomp-find-headers-end-point buffer)))
(let ((message ())
(headers-end-point (stomp-find-headers-end-point buffer))
(message-end-point (stomp-find-message-end-point buffer)))
(goto-char (point-min))
(map-put message 'command (current-word))
(setq headers (stomp-read-headers buffer headers-end-point))
;; TODO: take content-length header into account
(setq content (buffer-substring
(+ 1 headers-end-point)
(stomp-find-message-end-point buffer)))
(cond
(content
(map-put message 'headers headers)
(map-put message 'content content))
((and message-end-point headers-end-point)
(map-put message 'command (current-word))
(map-put message 'headers (stomp-read-headers buffer headers-end-point))
;; TODO: take content-length header into account
(map-put message 'content (buffer-substring (+ 1 headers-end-point) message-end-point)))
(t nil)))))
(defun stomp-read-headers (buffer end-point &optional headers)
@ -89,5 +83,6 @@
"Find the end of the header part of a STOMP frame."
(with-current-buffer buffer
(goto-char (point-min))
(search-forward-regexp "^$")
(line-end-position)))
(condition-case nil
(progn (search-forward-regexp "^$") (line-end-position))
(error nil))))

Loading…
Cancel
Save