1
0
Fork 0

- [GUI] added support for HTTP proxy;

- [fediverse] added 'edit-status'.
This commit is contained in:
cage 2024-06-26 12:49:36 +02:00
parent 883d2c0105
commit eb85a63430
11 changed files with 91 additions and 19 deletions

View File

@ -172,6 +172,14 @@ color-regexp = "\*[^*]+\*" #ffff00 bold
#color-regexp = "/[^/]+/" #ffff00 italic #color-regexp = "/[^/]+/" #ffff00 italic
gemini.search-engine.uri = "gemini://kennedy.gemi.dev/search"
# gemini proxy, forward all the gemini and http requests to the servel
# below, the response is converted, by the proxy, in a format fitted
# for a gemini client (e.g HTML is converted to gemtext)
gemini.proxy.uri = ""
# The width of the generated table of contents for gemini pages when # The width of the generated table of contents for gemini pages when
# tinmop is ran as exclusive gemini client (command line option "-G") # tinmop is ran as exclusive gemini client (command line option "-G")

View File

@ -547,6 +547,27 @@ database."
:spoiler-text subject :spoiler-text subject
:visibility visibility)) :visibility visibility))
(defun-api-call edit-status (content
attachments
attachments-alt-text
subject
language)
"Edit a status
- content the new text of the message
- attachments a list of file path to attach or nil il no attachments
to this message exists
- subject the subject of this message"
(tooter:edit-status *client*
content
:language language
:media (mapcar (lambda (path alt-text)
(tooter:make-media *client*
(fs:namestring->pathname path)
:description alt-text))
attachments
attachments-alt-text)
:spoiler-text subject))
(defun-api-call search-user (username &key (limit 1) (resolve nil)) (defun-api-call search-user (username &key (limit 1) (resolve nil))
"Find user identified by username" "Find user identified by username"
(tooter:search-accounts *client* username :limit limit :resolve resolve)) (tooter:search-accounts *client* username :limit limit :resolve resolve))

View File

@ -173,6 +173,8 @@ General Public License for more details."
(define-constant +file-scheme+ "file" :test #'string=) (define-constant +file-scheme+ "file" :test #'string=)
(define-constant +http-scheme+ "http" :test #'string=)
(define-constant +about-scheme+ "about" :test #'string=) (define-constant +about-scheme+ "about" :test #'string=)
(define-constant +internal-scheme-bookmark+ "bookmark" :test #'string=) (define-constant +internal-scheme-bookmark+ "bookmark" :test #'string=)

View File

@ -221,7 +221,7 @@
(defgeneric downloading-allowed-p (object)) (defgeneric downloading-allowed-p (object))
(defgeneric downloading-start-thread (object function host port path query fragment)) (defgeneric downloading-start-thread (object function scheme host port path query fragment))
(defmethod abort-downloading ((object gemini-stream)) (defmethod abort-downloading ((object gemini-stream))
(with-accessors ((download-thread-lock download-thread-lock)) object (with-accessors ((download-thread-lock download-thread-lock)) object
@ -252,6 +252,7 @@
(defmethod downloading-start-thread ((object gemini-stream) (defmethod downloading-start-thread ((object gemini-stream)
function function
scheme
host host
port port
path path
@ -265,6 +266,7 @@
(setf start-time (db-utils:local-time-obj-now)) (setf start-time (db-utils:local-time-obj-now))
(setf download-iri (gemini-parser:make-gemini-iri host (setf download-iri (gemini-parser:make-gemini-iri host
path path
:scheme scheme
:query query :query query
:port port :port port
:fragment fragment)) :fragment fragment))
@ -370,7 +372,7 @@
(text-utils:percent-decode fragment) (text-utils:percent-decode fragment)
fragment))) fragment)))
(defun request-stream-gemini-document-thread (wrapper-object host (defun request-stream-gemini-document-thread (wrapper-object scheme host
port path query fragment favicon port path query fragment favicon
gemini-format-p gemini-format-p
&key &key
@ -433,6 +435,7 @@
(with-open-support-file (file-stream support-file character) (with-open-support-file (file-stream support-file character)
(let* ((url (gemini-parser:make-gemini-iri host (let* ((url (gemini-parser:make-gemini-iri host
path path
:scheme scheme
:query query :query query
:port port :port port
:fragment fragment)) :fragment fragment))
@ -587,7 +590,7 @@
(if enqueue (if enqueue
:streaming :streaming
:running)))) :running))))
(multiple-value-bind (actual-iri host path query port fragment) (multiple-value-bind (actual-iri host path query port fragment scheme)
(gemini-client:displace-iri parsed-iri) (gemini-client:displace-iri parsed-iri)
(gemini-client:debug-gemini "response is a stream") (gemini-client:debug-gemini "response is a stream")
(labels ((make-text-based-stream (gemini-format-p) (labels ((make-text-based-stream (gemini-format-p)
@ -607,6 +610,7 @@
:download-socket socket)) :download-socket socket))
(favicon (fetch-favicon parsed-iri)) (favicon (fetch-favicon parsed-iri))
(thread-fn (request-stream-gemini-document-thread gemini-stream (thread-fn (request-stream-gemini-document-thread gemini-stream
scheme
host host
port port
path path
@ -619,6 +623,7 @@
(program-events:push-event enqueue-event) (program-events:push-event enqueue-event)
(downloading-start-thread gemini-stream (downloading-start-thread gemini-stream
thread-fn thread-fn
scheme
host host
port port
path path
@ -665,6 +670,7 @@
(program-events:push-event enqueue-event) (program-events:push-event enqueue-event)
(downloading-start-thread gemini-stream (downloading-start-thread gemini-stream
thread-fn thread-fn
scheme
host host
port port
path path
@ -683,7 +689,7 @@
(use-cached-file-if-exists nil) (use-cached-file-if-exists nil)
(do-nothing-if-exists-in-db nil)) (do-nothing-if-exists-in-db nil))
(labels ((get-user-input (hide-input url prompt) (labels ((get-user-input (hide-input url prompt)
(multiple-value-bind (actual-iri host path query port fragment) (multiple-value-bind (actual-iri host path query port fragment scheme)
(gemini-client:displace-iri (iri:iri-parse url)) (gemini-client:displace-iri (iri:iri-parse url))
(declare (ignore actual-iri query fragment)) (declare (ignore actual-iri query fragment))
(flet ((on-input-complete (input) (flet ((on-input-complete (input)
@ -692,6 +698,7 @@
(let ((encoded-input (maybe-percent-encode input))) (let ((encoded-input (maybe-percent-encode input)))
(request (gemini-parser:make-gemini-iri host (request (gemini-parser:make-gemini-iri host
path path
:scheme scheme
:query :query
encoded-input encoded-input
:port port) :port port)

View File

@ -441,6 +441,7 @@
:documentation "timeout, in seconds, for reading response from remote server") :documentation "timeout, in seconds, for reading response from remote server")
(defun request (host path &key (defun request (host path &key
(scheme +gemini-scheme+)
(query nil) (query nil)
(port +gemini-default-port+) (port +gemini-default-port+)
(fragment nil) (fragment nil)
@ -451,10 +452,12 @@
(swconf:config-gemini-proxy) (swconf:config-gemini-proxy)
(let* ((iri (make-gemini-iri (idn:host-unicode->ascii host) (let* ((iri (make-gemini-iri (idn:host-unicode->ascii host)
(percent-encode-path path) (percent-encode-path path)
:scheme scheme
:query (percent-encode-query query) :query (percent-encode-query query)
:port port :port port
:fragment (percent-encode-fragment fragment))) :fragment (percent-encode-fragment fragment)))
(ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+))) (ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+)))
;; (return-from request nil)
(cl+ssl:with-global-context (ctx :auto-free-p t) (cl+ssl:with-global-context (ctx :auto-free-p t)
(handler-case (handler-case
(let* ((actual-host (or proxy-host (let* ((actual-host (or proxy-host
@ -555,13 +558,16 @@
:certificate-key certificate-key :certificate-key certificate-key
:certificate-key-password certificate-key-password)))) :certificate-key-password certificate-key-password))))
(let ((parsed-iri (iri:iri-parse url))) (let ((parsed-iri (iri:iri-parse url)))
(multiple-value-bind (actual-iri host path query port) (multiple-value-bind (actual-iri host path query port x scheme)
(displace-iri parsed-iri) (displace-iri parsed-iri)
(declare (ignore x))
(multiple-value-bind (status code-description meta response socket) (multiple-value-bind (status code-description meta response socket)
(if (absolute-titan-url-p url) (if (absolute-titan-url-p url)
(make-titan-request) (make-titan-request)
(gemini-client:request host (gemini-client:request host
path path
:scheme (or scheme
+gemini-scheme+)
:certificate-key certificate-key :certificate-key certificate-key
:certificate-key-password certificate-key-password :certificate-key-password certificate-key-password
:client-certificate certificate :client-certificate certificate
@ -765,3 +771,8 @@ TODO: Add client certificate."
:ignore-warning t) :ignore-warning t)
(request-dispatch url dispatch-table)) (request-dispatch url dispatch-table))
(fs:slurp-file url :convert-to-string nil)))) (fs:slurp-file url :convert-to-string nil))))
(defun url-needs-proxy-p (url)
(and (swconf:config-gemini-proxy)
(string= (uri:scheme (iri:iri-parse url))
+http-scheme+)))

View File

@ -204,7 +204,8 @@
:clear-cache-certificate-password :clear-cache-certificate-password
:substitute-cache-certificate-password :substitute-cache-certificate-password
:build-redirect-iri :build-redirect-iri
:slurp-gemini-url)) :slurp-gemini-url
:url-needs-proxy-p))
(defpackage :gemini-dummy-server (defpackage :gemini-dummy-server
(:use (:use

View File

@ -1084,7 +1084,11 @@ local file paths."
(defun open-iri (iri main-window use-cache &key (status +stream-status-streaming+)) (defun open-iri (iri main-window use-cache &key (status +stream-status-streaming+))
(handler-case (handler-case
(let* ((actual-iri (remove-standard-port iri)) (let* ((actual-iri (remove-standard-port iri))
(parsed-iri (iri:iri-parse actual-iri))) (parsed-iri (iri:iri-parse actual-iri))
(needs-proxy (cev:enqueue-request-and-wait-results :gemini-url-needs-proxy-p
1
ev:+maximum-event-priority+
actual-iri)))
(cond (cond
((string= (uri:scheme parsed-iri) +internal-scheme-view-source+) ((string= (uri:scheme parsed-iri) +internal-scheme-view-source+)
(setf (uri:scheme parsed-iri) gemini-constants:+gemini-scheme+) (setf (uri:scheme parsed-iri) gemini-constants:+gemini-scheme+)
@ -1100,7 +1104,8 @@ local file paths."
(menu:manage-gemlogs)) (menu:manage-gemlogs))
((gemini-client:absolute-titan-url-p actual-iri) ((gemini-client:absolute-titan-url-p actual-iri)
(client-titan-window:init-window main-window main-window actual-iri)) (client-titan-window:init-window main-window main-window actual-iri))
((gemini-parser:gemini-iri-p actual-iri) ((or (gemini-parser:gemini-iri-p actual-iri)
needs-proxy)
(let ((stream-frame (stream-frame main-window))) (let ((stream-frame (stream-frame main-window)))
(start-stream-iri (iri-ensure-path actual-iri) (start-stream-iri (iri-ensure-path actual-iri)
main-window main-window
@ -1141,11 +1146,12 @@ local file paths."
:button-message button-label)) :button-message button-label))
(encoded-input (maybe-percent-encode raw-input))) (encoded-input (maybe-percent-encode raw-input)))
(when (string-not-empty-p raw-input) (when (string-not-empty-p raw-input)
(multiple-value-bind (actual-iri host path query port fragment) (multiple-value-bind (actual-iri host path query port fragment scheme)
(gemini-client:displace-iri parsed-iri) (gemini-client:displace-iri parsed-iri)
(declare (ignore actual-iri query fragment)) (declare (ignore actual-iri query fragment))
(gemini-parser:make-gemini-iri host (gemini-parser:make-gemini-iri host
path path
:scheme scheme
:query encoded-input :query encoded-input
:port port))))) :port port)))))

View File

@ -50,8 +50,13 @@
t) t)
(defun gemini-delete-tofu-certificate (iri) (defun gemini-delete-tofu-certificate (iri)
(multiple-value-bind (proxy-host x)
(swconf:config-gemini-proxy)
(declare (ignore x))
(if proxy-host
(db:tofu-delete proxy-host)
(let ((host (uri:host (iri:iri-parse iri)))) (let ((host (uri:host (iri:iri-parse iri))))
(db:tofu-delete host))) (db:tofu-delete host)))))
(defun gemini-import-certificate (uri cert-file key-file) (defun gemini-import-certificate (uri cert-file key-file)
(db-utils:with-ready-database (:connect nil) (db-utils:with-ready-database (:connect nil)

View File

@ -91,7 +91,7 @@
(defun request-success-dispatched-fn (status code-description meta response socket iri parsed-iri) (defun request-success-dispatched-fn (status code-description meta response socket iri parsed-iri)
(declare (ignore iri)) (declare (ignore iri))
(multiple-value-bind (actual-iri host path query port fragment) (multiple-value-bind (actual-iri host path query port fragment scheme)
(gemini-client:displace-iri parsed-iri) (gemini-client:displace-iri parsed-iri)
(debug-gemini-gui "response is a stream") (debug-gemini-gui "response is a stream")
(labels ((make-text-based-stream (gemini-format-p) (labels ((make-text-based-stream (gemini-format-p)
@ -112,6 +112,7 @@
:download-socket socket)) :download-socket socket))
(favicon (gemini-viewer::fetch-favicon parsed-iri)) (favicon (gemini-viewer::fetch-favicon parsed-iri))
(thread-fn (gemini-viewer::request-stream-gemini-document-thread gemini-stream (thread-fn (gemini-viewer::request-stream-gemini-document-thread gemini-stream
scheme
host host
port port
path path
@ -124,6 +125,7 @@
(gemini-viewer:push-db-stream gemini-stream) (gemini-viewer:push-db-stream gemini-stream)
(gemini-viewer::downloading-start-thread gemini-stream (gemini-viewer::downloading-start-thread gemini-stream
thread-fn thread-fn
scheme
host host
port port
path path
@ -167,6 +169,7 @@
(gemini-viewer:push-db-stream gemini-stream) (gemini-viewer:push-db-stream gemini-stream)
(gemini-viewer::downloading-start-thread gemini-stream (gemini-viewer::downloading-start-thread gemini-stream
thread-fn thread-fn
scheme
host host
port port
path path
@ -625,3 +628,6 @@
(defun titan-save-token (url token) (defun titan-save-token (url token)
(db:save-titan-token url token) (db:save-titan-token url token)
t) t)
(defun gemini-url-needs-proxy-p (url)
(gemini-client:url-needs-proxy-p url))

View File

@ -44,6 +44,9 @@
(gen-rpc "complete-net-address" (gen-rpc "complete-net-address"
'complete-net-address 'complete-net-address
"hint" 0) "hint" 0)
(gen-rpc "gemini-url-needs-proxy-p"
'gemini-url-needs-proxy-p
"iri" 0)
(gen-rpc "gemini-request" (gen-rpc "gemini-request"
'gemini-request 'gemini-request
"iri" 0 "iri" 0

View File

@ -74,6 +74,7 @@
:+octect-type+ :+octect-type+
:+gemini-file-extension+ :+gemini-file-extension+
:+file-scheme+ :+file-scheme+
:+http-scheme+
:+about-scheme+ :+about-scheme+
:+internal-scheme-bookmark+ :+internal-scheme-bookmark+
:+internal-scheme-gemlogs+ :+internal-scheme-gemlogs+
@ -1876,6 +1877,7 @@
:fetch-remote-status :fetch-remote-status
:get-remote-status :get-remote-status
:send-status :send-status
:edit-status
:get-status-context :get-status-context
:search-user :search-user
:find-results :find-results