1
0
Fork 0

- refactoring TOFU error recovery.

This commit is contained in:
cage 2021-06-18 17:10:58 +02:00
parent 4dae983197
commit f39e396762
4 changed files with 26 additions and 30 deletions

View File

@ -663,23 +663,13 @@
(push-url-to-history specials:*message-window* actual-iri)
(gemini-client:request-dispatch url gemini-client::dispatch-table)))))
(gemini-client:gemini-tofu-error (e)
(let ((host (gemini-client:host e)))
(flet ((on-input-complete (maybe-accepted)
(when (ui::boolean-input-accepted-p maybe-accepted)
(db-utils:with-ready-database (:connect nil)
(db:tofu-delete host)
(request url
:enqueue enqueue
:certificate certificate
:certificate-key certificate-key
:do-nothing-if-exists-in-db
do-nothing-if-exists-in-db)))))
(ui:ask-string-input #'on-input-complete
:prompt
(format nil
(_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ")
host)
:priority program-events:+standard-event-priority+))))
(gemini-client:with-ask-input-on-tofu-error (e)
(request url
:enqueue enqueue
:certificate certificate
:certificate-key certificate-key
:do-nothing-if-exists-in-db
do-nothing-if-exists-in-db)))
(conditions:not-implemented-error (e)
(ui:notify (format nil (_ "Error: ~a") e)
:as-error t))

View File

@ -523,3 +523,18 @@ TODO: Add client certificate."
:ignore-warning t)
(request-dispatch url dispatch-table))
(fs:slurp-file url :convert-to-string nil))))
(defmacro with-ask-input-on-tofu-error ((condition) &body body)
(with-gensyms (host)
`(let ((,host (gemini-client:host ,condition)))
(flet ((on-input-complete (maybe-accepted)
(when (ui::boolean-input-accepted-p maybe-accepted)
(db-utils:with-ready-database (:connect nil)
(db:tofu-delete ,host)
,@body))))
(ui:ask-string-input #'on-input-complete
:prompt
(format nil
(_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ")
,host)
:priority program-events:+standard-event-priority+)))))

View File

@ -147,7 +147,8 @@
:with-request-dispatch-table
:fetch-cached-certificate
:build-redirect-iri
:slurp-gemini-url))
:slurp-gemini-url
:with-ask-input-on-tofu-error))
(defpackage :gemini-subscription
(:use

View File

@ -86,15 +86,5 @@ be subscribed before (see: 'gemini-subscription:subcribe'"
date
nil))))))
(gemini-client:gemini-tofu-error (e)
(let ((host (gemini-client:host e)))
(flet ((on-input-complete (maybe-accepted)
(when (ui::boolean-input-accepted-p maybe-accepted)
(db-utils:with-ready-database (:connect nil)
(db:tofu-delete host)
(refresh url)))))
(ui:ask-string-input #'on-input-complete
:prompt
(format nil
(_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ")
host)
:priority program-events:+standard-event-priority+))))))
(with-ask-input-on-tofu-error (e)
(refresh url)))))