Basic read-only spartan implemented.
authorplugd <plugd@thelambdalab.xyz>
Thu, 5 May 2022 09:46:58 +0000 (11:46 +0200)
committerplugd <plugd@thelambdalab.xyz>
Thu, 5 May 2022 09:46:58 +0000 (11:46 +0200)
elpher.el

index 2a115e7..9540cee 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -91,7 +91,7 @@
     ((gopher ?s) elpher-get-gopher-page elpher-render-download "snd" elpher-binary)
     ((gopher ?h) elpher-get-gopher-page elpher-render-html "htm" elpher-html)
     (gemini elpher-get-gemini-page elpher-render-gemini "gem" elpher-gemini)
-    (spartan elpher-get-spartan-page elpher-render-spartan "spt" elpher-spartan)
+    (spartan elpher-get-spartan-page elpher-render-gemini "spt" elpher-spartan)
     (finger elpher-get-finger-page elpher-render-text "txt" elpher-text)
     (telnet elpher-get-telnet-page nil "tel" elpher-telnet)
     (other-url elpher-get-other-url-page nil "url" elpher-other-url)
@@ -424,6 +424,7 @@ address refers to, via the table `elpher-type-map'."
                ?1
              (string-to-char (substring (url-filename address) 1)))))
     ("gemini" 'gemini)
+    ("spartan" 'spartan)
     ("telnet" 'telnet)
     ("finger" 'finger)
     ("file" 'file)
@@ -1698,6 +1699,8 @@ can be used to toggle the display of the preformatted text."
 
 ;; Spartan page retrieval
 
+(defvar elpher-spartan-redirect-chain)
+
 (defun elpher-get-spartan-page (renderer)
   "Getter which retrieves and renders a Spartan page and renders it using RENDERER."
   (let* ((address (elpher-page-address elpher-current-page))
@@ -1709,7 +1712,7 @@ can be used to toggle the display of the preformatted text."
              (elpher-restore-pos))
           (elpher-with-clean-buffer
            (insert "LOADING GEMINI... (use 'u' to cancel)\n"))
-          (setq elpher-gemini-redirect-chain nil)
+          (setq elpher-spartan-redirect-chain nil)
           (elpher-get-spartan-response address renderer))
       (error
        (elpher-network-error address the-error)))))
@@ -1749,38 +1752,29 @@ that the response was malformed."
          (funcall renderer response-body response-meta))
         (?3 ; Redirect
          (message "Following redirect to %s" response-meta)
-         (if (>= (length elpher-gemini-redirect-chain) 5)
+         (if (>= (length elpher-spartan-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)
+         (let* ((current-address (elpher-page-address current-page))
+                (redirect-address (elpher-address-from-url
+                                   (concat "spartan://"
+                                           (elpher-address-host current-address)
+                                           ":"
+                                           (elpher-address-port current-address)
+                                           "/"
+                                           response-meta))))
+           (if (member redirect-address elpher-spartan-redirect-chain)
                (error "Redirect loop detected"))
-           (if (not (eq (elpher-address-type redirect-address) 'gemini))
-               (error "Server tried to automatically redirect to non-gemini URL: %s"
-                      response-meta))
            (elpher-page-set-address elpher-current-page redirect-address)
            (add-to-list 'elpher-gemini-redirect-chain redirect-address)
-           (elpher-get-gemini-response redirect-address renderer)))
+           (elpher-get-spartan-response redirect-address renderer)))
         (?4 ; Temporary failure
-         (error "Gemini server reports TEMPORARY FAILURE for this request: %s %s"
+         (error "Spartan server reports CLIENT ERROR for this request: %s %s"
                 response-code response-meta))
         (?5 ; Permanent failure
-         (error "Gemini server reports PERMANENT FAILURE for this request: %s %s"
+         (error "Spartan server reports SERVER ERROR for this request: %s %s"
                 response-code response-meta))
-        (?6 ; Client certificate required
-         (elpher-with-clean-buffer
-          (if elpher-client-certificate
-              (insert "Gemini server does not recognise the provided TLS certificate:\n\n")
-            (insert "Gemini server is requesting a valid TLS certificate:\n\n"))
-          (auto-fill-mode 1)
-          (elpher-gemini-insert-text response-meta))
-         (let ((chosen-certificate (elpher-choose-client-certificate)))
-           (unless chosen-certificate
-             (error "Gemini server requires a client certificate and none was provided"))
-           (setq elpher-client-certificate chosen-certificate))
-         (elpher-with-clean-buffer)
-         (elpher-get-gemini-response (elpher-page-address elpher-current-page) renderer))
         (_other
-         (error "Gemini server response unknown: %s %s"
+         (error "Spartan server response unknown: %s %s"
                 response-code response-meta))))))
 
 ;; Finger page connection