aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-09-24 08:33:39 +0200
committerLars Ingebrigtsen2019-09-24 08:33:45 +0200
commit61a2b3ca7d4afe3e3f77b77f59de3ad2f7159bfd (patch)
treee3036e5dc0768445fbaa949a05c50993deb4e6e7
parentd3f8279422f12cff8e90254d872d2afcb9da021d (diff)
downloademacs-61a2b3ca7d4afe3e3f77b77f59de3ad2f7159bfd.tar.gz
emacs-61a2b3ca7d4afe3e3f77b77f59de3ad2f7159bfd.zip
Allow scrolling the NSM window
* lisp/net/nsm.el (nsm-query-user): Allow moving backwards/forwards in the NSM buffer if the window is too small to show all the details (bug#28069).
-rw-r--r--lisp/net/nsm.el170
1 files changed, 98 insertions, 72 deletions
diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el
index 11535a5a5a1..b8c84d5fdea 100644
--- a/lisp/net/nsm.el
+++ b/lisp/net/nsm.el
@@ -815,84 +815,110 @@ protocol."
815(defun nsm-query-user (message status) 815(defun nsm-query-user (message status)
816 (let ((buffer (get-buffer-create "*Network Security Manager*")) 816 (let ((buffer (get-buffer-create "*Network Security Manager*"))
817 (cert-buffer (get-buffer-create "*Certificate Details*")) 817 (cert-buffer (get-buffer-create "*Certificate Details*"))
818 (certs (plist-get status :certificates))) 818 (certs (plist-get status :certificates))
819 (accept-choices
820 '((?a "always" "Accept this certificate this session and for all future sessions.")
821 (?s "session only" "Accept this certificate this session only.")
822 (?n "no" "Refuse to use this certificate, and close the connection.")
823 (?d "details" "See certificate details")))
824 (details-choices
825 '((?b "backward page" "See previous page")
826 (?f "forward page" "See next page")
827 (?n "next" "Next certificate")
828 (?p "previous" "Previous certificate")
829 (?q "quit" "Quit details view")))
830 (done nil))
819 (save-window-excursion 831 (save-window-excursion
820 ;; First format the certificate and warnings. 832 ;; First format the certificate and warnings.
821 (with-current-buffer-window 833 (pop-to-buffer buffer)
822 buffer nil nil 834 (erase-buffer)
823 (when status (insert (nsm-format-certificate status))) 835 (let ((inhibit-read-only t))
824 (insert message) 836 (when status
825 (goto-char (point-min)) 837 (insert (nsm-format-certificate status)))
826 ;; Fill the first line of the message, which usually 838 (insert message)
827 ;; contains lots of explanatory text. 839 (goto-char (point-min))
828 (fill-region (point) (line-end-position))) 840 ;; Fill the first line of the message, which usually
841 ;; contains lots of explanatory text.
842 (fill-region (point) (line-end-position))
843 ;; If the window is too small, add navigation options.
844 (when (> (line-number-at-pos (point-max)) (window-height))
845 (setq accept-choices
846 (append accept-choices
847 '((?b "backward page" "See previous page")
848 (?f "forward page" "See next page"))))))
829 ;; Then ask the user what to do about it. 849 ;; Then ask the user what to do about it.
830 (unwind-protect 850 (unwind-protect
831 (let* ((accept-choices '((?a "always" "Accept this certificate this session and for all future sessions.") 851 (let* ((pems (cl-loop for cert in certs
832 (?s "session only" "Accept this certificate this session only.")
833 (?n "no" "Refuse to use this certificate, and close the connection.")
834 (?d "details" "See certificate details")))
835 (details-choices '((?b "backward page" "See previous page")
836 (?f "forward page" "See next page")
837 (?n "next" "Next certificate")
838 (?p "previous" "Previous certificate")
839 (?q "quit" "Quit details view")))
840 (answer (read-multiple-choice "Continue connecting?"
841 accept-choices))
842 (show-details (char-equal (car answer) ?d))
843 (pems (cl-loop for cert in certs
844 collect (gnutls-format-certificate 852 collect (gnutls-format-certificate
845 (plist-get cert :pem)))) 853 (plist-get cert :pem))))
846 (cert-index 0)) 854 (cert-index 0)
847 (while show-details 855 show-details answer buf)
848 (unless (get-buffer-window cert-buffer) 856 (while (not done)
849 (set-window-buffer (get-buffer-window buffer) cert-buffer) 857 (setq answer (if show-details
850 (with-current-buffer cert-buffer 858 (read-multiple-choice "Viewing certificate:"
851 (read-only-mode -1) 859 details-choices)
852 (insert (nth cert-index pems)) 860 (read-multiple-choice "Continue connecting?"
853 (goto-char (point-min)) 861 accept-choices)))
854 (read-only-mode))) 862 (setq buf (if show-details cert-buffer buffer))
855 863
856 (setq answer (read-multiple-choice "Viewing certificate:" details-choices)) 864 (cl-case (car answer)
857 865 (?q
858 (cond 866 ;; Exit the details window.
859 ((char-equal (car answer) ?q) 867 (set-window-buffer (get-buffer-window cert-buffer) buffer)
860 (setq show-details (not show-details)) 868 (setq show-details nil))
861 (set-window-buffer (get-buffer-window cert-buffer) buffer) 869
862 (setq show-details (char-equal 870 (?d
863 (car (setq answer 871 ;; Enter the details window.
864 (read-multiple-choice 872 (set-window-buffer (get-buffer-window buffer) cert-buffer)
865 "Continue connecting?" 873 (with-current-buffer cert-buffer
866 accept-choices))) 874 (read-only-mode -1)
867 ?d))) 875 (insert (nth cert-index pems))
868 876 (goto-char (point-min))
869 ((char-equal (car answer) ?b) 877 (read-only-mode))
870 (with-selected-window (get-buffer-window cert-buffer) 878 (setq show-details t))
871 (with-current-buffer cert-buffer 879
872 (ignore-errors (scroll-down))))) 880 (?b
873 881 ;; Scroll down.
874 ((char-equal (car answer) ?f) 882 (with-selected-window (get-buffer-window buf)
875 (with-selected-window (get-buffer-window cert-buffer) 883 (with-current-buffer buf
876 (with-current-buffer cert-buffer 884 (ignore-errors (scroll-down)))))
877 (ignore-errors (scroll-up))))) 885
878 886 (?f
879 ((char-equal (car answer) ?n) 887 ;; Scroll up.
880 (with-current-buffer cert-buffer 888 (with-selected-window (get-buffer-window buf)
881 (read-only-mode -1) 889 (with-current-buffer buf
882 (erase-buffer) 890 (ignore-errors (scroll-up)))))
883 (setq cert-index (mod (1+ cert-index) (length pems))) 891
884 (insert (nth cert-index pems)) 892 (?n
885 (goto-char (point-min)) 893 ;; "No" or "next certificate".
886 (read-only-mode))) 894 (if show-details
887 895 (with-current-buffer cert-buffer
888 ((char-equal (car answer) ?p) 896 (read-only-mode -1)
889 (with-current-buffer cert-buffer 897 (erase-buffer)
890 (read-only-mode -1) 898 (setq cert-index (mod (1+ cert-index) (length pems)))
891 (erase-buffer) 899 (insert (nth cert-index pems))
892 (setq cert-index (mod (1- cert-index) (length pems))) 900 (goto-char (point-min))
893 (insert (nth cert-index pems)) 901 (read-only-mode))
894 (goto-char (point-min)) 902 (setq done t)))
895 (read-only-mode))))) 903
904 (?a
905 ;; "Always"
906 (setq done t))
907
908 (?s
909 ;; "Session only"
910 (setq done t))
911
912 (?p
913 ;; Previous certificate.
914 (with-current-buffer cert-buffer
915 (read-only-mode -1)
916 (erase-buffer)
917 (setq cert-index (mod (1- cert-index) (length pems)))
918 (insert (nth cert-index pems))
919 (goto-char (point-min))
920 (read-only-mode)))))
921 ;; Return the answer.
896 (cadr answer)) 922 (cadr answer))
897 (kill-buffer cert-buffer) 923 (kill-buffer cert-buffer)
898 (kill-buffer buffer))))) 924 (kill-buffer buffer)))))