-;;; Gopher selector retrieval (all kinds)
-;;
-
-(defun elpher-process-cleanup ()
- "Immediately shut down any extant elpher process."
- (let ((p (get-process "elpher-process")))
- (if p (delete-process p))))
-
-(defvar elpher-use-tls nil
- "If non-nil, use TLS to communicate with gopher servers.")
-
-(defvar elpher-selector-string)
-
-(defun elpher-get-selector (address after &optional propagate-error)
- "Retrieve selector specified by ADDRESS, then execute AFTER.
-The result is stored as a string in the variable ‘elpher-selector-string’.
-
-Usually errors result in an error page being displayed. This is only
-appropriate if the selector is to be directly viewed. If PROPAGATE-ERROR
-is non-nil, this message is not displayed. Instead, the error propagates
-up to the calling function."
- (setq elpher-selector-string "")
- (when (equal (elpher-address-protocol address) "gophers")
- (if (gnutls-available-p)
- (when (not elpher-use-tls)
- (setq elpher-use-tls t)
- (message "Engaging TLS mode."))
- (error "Cannot retrieve TLS selector: GnuTLS not available")))
- (condition-case the-error
- (let* ((kill-buffer-query-functions nil)
- (proc (open-network-stream "elpher-process"
- nil
- (elpher-address-host address)
- (elpher-address-port address)
- :type (if elpher-use-tls 'tls 'plain))))
- (set-process-coding-system proc 'binary)
- (set-process-filter proc
- (lambda (proc string)
- (setq elpher-selector-string
- (concat elpher-selector-string string))))
- (set-process-sentinel proc after)
- (process-send-string proc
- (concat (elpher-gopher-address-selector address) "\n")))
- (error
- (if (and (consp the-error)
- (eq (car the-error) 'gnutls-error)
- (not (equal (elpher-address-protocol address) "gophers"))
- (or elpher-auto-disengage-TLS
- (yes-or-no-p "Could not establish encrypted connection. Disable TLS mode? ")))
- (progn
- (message "Disengaging TLS mode.")
- (setq elpher-use-tls nil)
- (elpher-get-selector address after))
- (elpher-process-cleanup)
- (if propagate-error
- (error the-error)
- (elpher-with-clean-buffer
- (insert (propertize "\n---- ERROR -----\n\n" 'face 'error)
- "Failed to connect to " (elpher-address-to-url address) ".\n"
- (propertize "\n----------------\n\n" 'face 'error)
- "Press 'u' to return to the previous page.")))))))
-
-;; Index retrieval
-
-(defun elpher-get-index-node ()
- "Getter which retrieves the current node contents as an index."
- (let* ((address (elpher-node-address elpher-current-node))
- (content (elpher-get-cached-content address)))
- (if content
- (progn
- (elpher-with-clean-buffer
- (insert content)
- (elpher-restore-pos)))
- (elpher-with-clean-buffer
- (insert "LOADING DIRECTORY... (use 'u' to cancel)"))
- (elpher-get-selector address
- (lambda (proc event)
- (unless (string-prefix-p "deleted" event)
- (elpher-with-clean-buffer
- (elpher-insert-index elpher-selector-string)
- (elpher-restore-pos)
- (elpher-cache-content
- (elpher-node-address elpher-current-node)
- (buffer-string)))))))))
-
-;; Text retrieval