X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=elpher.el;h=db5a82019a6d767a4654b944b35b826c31b9f133;hb=bf4ca5f27dee02b0cc38633c1fe66b8891e6282c;hp=eaa112391db2d32f83cb536aef3f272c8af85e82;hpb=e24ed079befa8284c02ec9cb53231a2d70e66a4b;p=elpher.git diff --git a/elpher.el b/elpher.el index eaa1123..db5a820 100644 --- a/elpher.el +++ b/elpher.el @@ -4,7 +4,7 @@ ;; Author: Tim Vaughan ;; Created: 11 April 2019 -;; Version: 2.3.5 +;; Version: 2.3.6 ;; Keywords: comm gopher ;; Homepage: https://github.com/tgvaughan/elpher ;; Package-Requires: ((emacs "26")) @@ -60,12 +60,13 @@ (require 'shr) (require 'url-util) (require 'subr-x) +(require 'dns) ;;; Global constants ;; -(defconst elpher-version "2.3.5" +(defconst elpher-version "2.3.6" "Current version of elpher.") (defconst elpher-margin-width 6 @@ -282,16 +283,11 @@ For gopher addresses this is a combination of the selector type and selector." (url-host address)) (defun elpher-address-port (address) - "Retrieve port from ADDRESS object." + "Retrieve port from ADDRESS object. +If no address is defined, returns 0. (This is for compatibility with the URL library.)" (if (symbolp address) - nil) - (if (> (url-port address) 0) - (url-port address) - (or (and (or (equal (url-type address) "gopher") - (equal (url-type address) "gophers")) - 70) - (and (equal (url-type address) "gemini") - 1965)))) + 0 + (url-port address))) (defun elpher-address-special-p (address) "Return non-nil if ADDRESS object is special (e.g. start page, bookmarks page)." @@ -509,10 +505,12 @@ up to the calling function." (error "Cannot retrieve TLS gopher selector: GnuTLS not available"))) (condition-case the-error (let* ((kill-buffer-query-functions nil) + (port (elpher-address-port address)) + (host (elpher-address-host address)) (proc (open-network-stream "elpher-process" nil - (elpher-address-host address) - (elpher-address-port address) + host + (if (> port 0) port 70) :type (if elpher-use-tls 'tls 'plain)))) (set-process-coding-system proc 'binary) (set-process-filter proc @@ -774,6 +772,7 @@ The response is rendered using the rendering function RENDERER." ;; Gemini node retrieval (defvar elpher-gemini-response) +(defvar elpher-gemini-redirect-chain) (defun elpher-get-gemini-response (address after) "Retrieve gemini ADDRESS, then execute AFTER. @@ -784,11 +783,14 @@ The response is stored in the variable ‘elpher-gemini-response’." (condition-case the-error (let* ((kill-buffer-query-functions nil) (network-security-level 'medium) + (port (elpher-address-port address)) + (host (elpher-address-host address)) (proc (open-network-stream "elpher-process" nil - (elpher-address-host address) - (elpher-address-port address) - :type 'tls))) + host + (if (> port 0) port 1965) + :type 'tls + :nowait t))) (set-process-coding-system proc 'binary) (set-process-filter proc (lambda (_proc string) @@ -834,7 +836,8 @@ The response is assumed to be in the variable `elpher-gemini-response'." (query-address (elpher-address-from-url (concat url "?" query-string)))) (elpher-get-gemini-response query-address (lambda (_proc event) - (unless (string-prefix-p "deleted" event) + (unless (or (string-prefix-p "deleted" event) + (string-prefix-p "open" event)) (funcall #'elpher-process-gemini-response renderer) (elpher-restore-pos)))))) @@ -843,10 +846,20 @@ The response is assumed to be in the variable `elpher-gemini-response'." (funcall renderer response-body response-meta)) (?3 ; Redirect (message "Following redirect to %s" response-meta) + (if (>= (length elpher-gemini-redirect-chain) 5) + (error "More than 5 consecutive redirects followed")) (let ((redirect-address (elpher-address-from-gemini-url response-meta))) + (if (member redirect-address elpher-gemini-redirect-chain) + (error "Redirect loop detected")) + (if (not (string= (elpher-address-protocol redirect-address) + "gemini")) + (error "Server tried to automatically redirect to non-gemini URL: %s" + response-meta)) + (add-to-list 'elpher-gemini-redirect-chain redirect-address) (elpher-get-gemini-response redirect-address (lambda (_proc event) - (unless (string-prefix-p "deleted" event) + (unless (or (string-prefix-p "deleted" event) + (string-prefix-p "open" event)) (funcall #'elpher-process-gemini-response renderer) (elpher-restore-pos)))))) @@ -875,9 +888,11 @@ The response is assumed to be in the variable `elpher-gemini-response'." (elpher-restore-pos)) (elpher-with-clean-buffer (insert "LOADING GEMINI... (use 'u' to cancel)")) + (setq elpher-gemini-redirect-chain nil) (elpher-get-gemini-response address (lambda (_proc event) - (unless (string-prefix-p "deleted" event) + (unless (or (string-prefix-p "deleted" event) + (string-prefix-p "open" event)) (funcall #'elpher-process-gemini-response renderer) (elpher-restore-pos))))) @@ -1012,7 +1027,9 @@ For instance, the filename /a/b/../c/./d will reduce to /a/c/d" (host (elpher-address-host address)) (port (elpher-address-port address))) (elpher-visit-parent-node) - (telnet host port))) + (if (> port 0) + (telnet host port) + (telnet host)))) ;; Start page node retrieval