;; Author: Tim Vaughan <tgvaughan@gmail.com>
;; 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"))
;;; Global constants
;;
-(defconst elpher-version "2.3.5"
+(defconst elpher-version "2.3.6"
"Current version of elpher.")
(defconst elpher-margin-width 6
(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)."
(error "Cannot retrieve TLS gopher selector: GnuTLS not available")))
(condition-case the-error
(let* ((kill-buffer-query-functions nil)
+ (port (elpher-address-port address))
(proc (open-network-stream "elpher-process"
nil
(elpher-address-host address)
- (elpher-address-port address)
+ (if (> port 0) port 70)
:type (if elpher-use-tls 'tls 'plain))))
(set-process-coding-system proc 'binary)
(set-process-filter proc
;; 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.
(condition-case the-error
(let* ((kill-buffer-query-functions nil)
(network-security-level 'medium)
+ (port (elpher-address-port address))
(proc (open-network-stream "elpher-process"
nil
(elpher-address-host address)
- (elpher-address-port address)
+ (if (> port 0) port 1965)
:type 'tls)))
(set-process-coding-system proc 'binary)
(set-process-filter proc
(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)
(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)
(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