From 0c2398c184fd4fe04aa9db1e96a7de24f5e1764a Mon Sep 17 00:00:00 2001 From: cage Date: Mon, 15 Mar 2021 19:28:07 +0100 Subject: [PATCH] - fixed hex digit parsing from iri parser; - added more debugging messages; - fixed formatting. --- src/gemini-viewer.lisp | 26 +++++++++++++------------- src/gemini/client.lisp | 1 + src/iri-parser.lisp | 4 +++- src/os-utils.lisp | 6 ++++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/gemini-viewer.lisp b/src/gemini-viewer.lisp index ee32d3e..ea3ce9e 100644 --- a/src/gemini-viewer.lisp +++ b/src/gemini-viewer.lisp @@ -413,19 +413,19 @@ (with-open-support-file (file-stream support-file) (labels ((%fill-buffer () (when (downloading-allowed-p wrapper-object) - (multiple-value-bind (buffer read-so-far) - (read-array download-stream +read-buffer-size+) - (increment-bytes-count wrapper-object read-so-far) - (if (< read-so-far (length buffer)) - (progn - (write-sequence buffer file-stream :start 0 :end read-so-far) - (force-output file-stream) - (setf (stream-status wrapper-object) :completed) - (gemini-client:close-ssl-socket socket) - (os-utils:xdg-open support-file)) - (progn - (write-sequence buffer file-stream) - (%fill-buffer))))))) + (multiple-value-bind (buffer read-so-far) + (read-array download-stream +read-buffer-size+) + (increment-bytes-count wrapper-object read-so-far) + (if (< read-so-far (length buffer)) + (progn + (write-sequence buffer file-stream :start 0 :end read-so-far) + (force-output file-stream) + (setf (stream-status wrapper-object) :completed) + (gemini-client:close-ssl-socket socket) + (os-utils:xdg-open support-file)) + (progn + (write-sequence buffer file-stream) + (%fill-buffer))))))) (%fill-buffer)))))) (defun request-success-dispatched-clrs (enqueue) diff --git a/src/gemini/client.lisp b/src/gemini/client.lisp index 75a1e76..90eef75 100644 --- a/src/gemini/client.lisp +++ b/src/gemini/client.lisp @@ -243,6 +243,7 @@ (let* ((header-raw (read-line-into-array stream :add-newline-stopper nil)) (header (babel:octets-to-string header-raw :errorp nil)) (parsed-header (parse-gemini-response-header (format nil "~a~a" header #\Newline)))) + (debug-gemini (format nil "response header ~s" header)) (with-accessors ((meta meta) (status-code status-code)) parsed-header (flet ((results (code-class body) diff --git a/src/iri-parser.lisp b/src/iri-parser.lisp index be20b5b..7043ca7 100644 --- a/src/iri-parser.lisp +++ b/src/iri-parser.lisp @@ -110,7 +110,9 @@ (defrule pct-encoded (and "%" hexdig hexdig) (:text t)) -(defrule hexdig (or (character-ranges #\a #\f) digit) +(defrule hexdig (or (character-ranges (#\a #\f)) + (character-ranges (#\A #\F)) + digit) (:text t)) (defrule ipv4-address (and dec-octet "." dec-octet "." dec-octet "." dec-octet) diff --git a/src/os-utils.lisp b/src/os-utils.lisp index f6e3f4e..07d98d2 100644 --- a/src/os-utils.lisp +++ b/src/os-utils.lisp @@ -44,8 +44,10 @@ (incf cpu-count))))) (defun xdg-open (file) - (uiop:launch-program (format nil "~a '~a'" +xdg-open-bin+ file) - :output nil)) + (let ((cmd-line (format nil "~a '~a'" +xdg-open-bin+ file))) + #+debug-mode + (misc:dbg "xdg-open: ~a" cmd-line) + (uiop:launch-program cmd-line :output nil))) (defun getenv (name) (nix:getenv name))