diff options
Diffstat (limited to 'lisp/url')
-rw-r--r-- | lisp/url/url-auth.el | 30 | ||||
-rw-r--r-- | lisp/url/url-cookie.el | 10 | ||||
-rw-r--r-- | lisp/url/url-dired.el | 10 | ||||
-rw-r--r-- | lisp/url/url-file.el | 30 | ||||
-rw-r--r-- | lisp/url/url-handlers.el | 3 | ||||
-rw-r--r-- | lisp/url/url-http.el | 208 | ||||
-rw-r--r-- | lisp/url/url-privacy.el | 1 | ||||
-rw-r--r-- | lisp/url/url-queue.el | 15 | ||||
-rw-r--r-- | lisp/url/url-util.el | 7 | ||||
-rw-r--r-- | lisp/url/url-vars.el | 22 |
10 files changed, 186 insertions, 150 deletions
diff --git a/lisp/url/url-auth.el b/lisp/url/url-auth.el index 585010d21c5..53cefb46e4b 100644 --- a/lisp/url/url-auth.el +++ b/lisp/url/url-auth.el @@ -87,11 +87,13 @@ instead of the filename inheritance method." ((and prompt (not byserv)) (setq user (or (url-do-auth-source-search server type :user) - (read-string (url-auth-user-prompt href realm) - (or user (user-real-login-name)))) + (and (url-interactive-p) + (read-string (url-auth-user-prompt href realm) + (or user (user-real-login-name))))) pass (or (url-do-auth-source-search server type :secret) - (read-passwd "Password: " nil (or pass "")))) + (and (url-interactive-p) + (read-passwd "Password: " nil (or pass ""))))) (set url-basic-auth-storage (cons (list server (cons file @@ -117,11 +119,13 @@ instead of the filename inheritance method." (progn (setq user (or (url-do-auth-source-search server type :user) - (read-string (url-auth-user-prompt href realm) - (user-real-login-name))) + (and (url-interactive-p) + (read-string (url-auth-user-prompt href realm) + (user-real-login-name)))) pass (or (url-do-auth-source-search server type :secret) - (read-passwd "Password: ")) + (and (url-interactive-p) + (read-passwd "Password: "))) retval (base64-encode-string (format "%s:%s" user pass) t) byserv (assoc server (symbol-value url-basic-auth-storage))) (setcdr byserv @@ -233,11 +237,13 @@ CREDS is a plist that may have properties `:user' and `:secret'." ;; plist-put modify the same plist. (setq creds (plist-put creds :user - (read-string (url-auth-user-prompt url realm) - (or (plist-get creds :user) - (user-real-login-name))))) + (and (url-interactive-p) + (read-string (url-auth-user-prompt url realm) + (or (plist-get creds :user) + (user-real-login-name)))))) (plist-put creds :secret - (read-passwd "Password: " nil (plist-get creds :secret)))) + (and (url-interactive-p) + (read-passwd "Password: " nil (plist-get creds :secret))))) (defun url-digest-auth-directory-id-assoc (dirkey keylist) "Find the best match for DIRKEY in key alist KEYLIST. @@ -301,8 +307,8 @@ object." (defun url-digest-auth-build-response (key url realm attrs) "Compute authorization string for the given challenge using KEY. -The string looks like 'Digest username=\"John\", realm=\"The -Realm\", ...' +The string looks like \"Digest username=\"John\", realm=\"The +Realm\", ...\" Part of the challenge is already solved in a pre-computed KEY which is list of a realm (or a directory), user name, and hash diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index 6b9ce5da93e..42e1fa22fac 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el @@ -494,12 +494,10 @@ Use \\<url-cookie-mode-map>\\[url-cookie-delete] to remove cookies." (url-cookie--generate-buffer) (goto-char point)))) -(defvar url-cookie-mode-map - (let ((map (make-sparse-keymap))) - (define-key map [delete] 'url-cookie-delete) - (define-key map [(control k)] 'url-cookie-delete) - (define-key map [(control _)] 'url-cookie-undo) - map)) +(defvar-keymap url-cookie-mode-map + "<delete>" #'url-cookie-delete + "C-k" #'url-cookie-delete + "C-_" #'url-cookie-undo) (define-derived-mode url-cookie-mode special-mode "URL Cookie" "Mode for listing cookies. diff --git a/lisp/url/url-dired.el b/lisp/url/url-dired.el index 1bbd741c1a7..e2c23a8b6d9 100644 --- a/lisp/url/url-dired.el +++ b/lisp/url/url-dired.el @@ -25,12 +25,10 @@ (autoload 'dired-get-filename "dired") -(defvar url-dired-minor-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "\C-m" 'url-dired-find-file) - (define-key map [mouse-2] 'url-dired-find-file-mouse) - map) - "Keymap used when browsing directories.") +(defvar-keymap url-dired-minor-mode-map + :doc "Keymap used when browsing directories." + "C-m" #'url-dired-find-file + "<mouse-2>" #'url-dired-find-file-mouse) (defun url-dired-find-file () "In dired, visit the file or directory named on this line." diff --git a/lisp/url/url-file.el b/lisp/url/url-file.el index 31e5c07234c..3863ac99144 100644 --- a/lisp/url/url-file.el +++ b/lisp/url/url-file.el @@ -29,6 +29,12 @@ (require 'url-dired) (declare-function mm-disable-multibyte "mm-util" ()) +(defvar url-allow-non-local-files nil + "If non-nil, allow URL to fetch non-local files. +By default, this is not allowed, since that would allow rendering +HTML to fetch files on other systems if given a <img +src=\"/ssh:host...\"> element, which can be disturbing.") + (defconst url-file-default-port 21 "Default FTP port.") (defconst url-file-asynchronous-p t "FTP transfers are asynchronous.") (defalias 'url-file-expand-file-name 'url-default-expander) @@ -70,18 +76,15 @@ to them." buff func func args args efs)) - (let ((size (file-attribute-size (file-attributes name)))) - (with-current-buffer buff - (goto-char (point-max)) - (if (/= -1 size) - (insert (format "Content-length: %d\n" size))) - (insert "\n") - (insert-file-contents-literally name) - (if (not (url-file-host-is-local-p (url-host url-current-object))) - (condition-case () - (delete-file name) - (error nil))) - (apply func args)))) + (with-current-buffer buff + (goto-char (point-max)) + (insert-file-contents-literally name) + (insert (format "Content-length: %d\n\n" (buffer-size))) + (if (not (url-file-host-is-local-p (url-host url-current-object))) + (condition-case () + (delete-file name) + (error nil))) + (apply func args))) (declare-function ange-ftp-set-passwd "ange-ftp" (host user passwd)) (declare-function ange-ftp-copy-file-internal "ange-ftp" @@ -111,7 +114,8 @@ to them." (memq system-type '(ms-dos windows-nt))) (substring file 1)) ;; file: URL with a file:/bar:/foo-like spec. - ((string-match "\\`/[^/]+:/" file) + ((and (not url-allow-non-local-files) + (string-match "\\`/[^/]+:/" file)) (concat "/:" file)) (t file)))) diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index 2da24ff6042..74f77cd2383 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el @@ -396,7 +396,8 @@ if it had been inserted from a file named URL." (url-handlers-create-wrapper file-writable-p (url)) (url-handlers-create-wrapper file-directory-p (url)) (url-handlers-create-wrapper file-executable-p (url)) -(url-handlers-create-wrapper directory-files (url &optional full match nosort)) +(url-handlers-create-wrapper + directory-files (url &optional full match nosort count)) (url-handlers-create-wrapper file-truename (url &optional counter prev-dirs)) (add-hook 'find-file-hook #'url-handlers-set-buffer-mode) diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index 16c3a6a1e62..4e5d017036c 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el @@ -36,6 +36,7 @@ (defvar url-current-object) (defvar url-http-after-change-function) (defvar url-http-chunked-counter) +(defvar url-http-chunked-last-crlf-missing) (defvar url-http-chunked-length) (defvar url-http-chunked-start) (defvar url-http-connection-opened) @@ -332,7 +333,10 @@ Use `url-http-referer' as the Referer-header (subject to `url-privacy-level')." (if (and using-proxy ;; Bug#35969. (not (equal "https" (url-type url-http-target-url)))) - (url-recreate-url url-http-target-url) real-fname)) + (let ((url (copy-sequence url-http-target-url))) + (setf (url-host url) (puny-encode-domain (url-host url))) + (url-recreate-url url)) + real-fname)) " HTTP/" url-http-version "\r\n" ;; Version of MIME we speak "MIME-Version: 1.0\r\n" @@ -585,6 +589,13 @@ should be shown to the user." (url-http-debug "url-http-parse-headers called in (%s)" (buffer-name)) (url-http-parse-response) (mail-narrow-to-head) + (when url-debug + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (url-http-debug "Response: %s" + (buffer-substring (point) (line-end-position))) + (forward-line 1)))) ;;(narrow-to-region (point-min) url-http-end-of-headers) (let ((connection (mail-fetch-field "Connection"))) ;; In HTTP 1.0, keep the connection only if there is a @@ -1068,90 +1079,105 @@ the callback to be triggered." Cannot give a sophisticated percentage, but we need a different function to look for the special 0-length chunk that signifies the end of the document." - (save-excursion - (goto-char st) - (let ((read-next-chunk t) - (case-fold-search t) - (regexp nil) - (no-initial-crlf nil)) - ;; We need to loop thru looking for more chunks even within - ;; one after-change-function call. - (while read-next-chunk - (setq no-initial-crlf (= 0 url-http-chunked-counter)) - (if url-http-content-type + (if url-http-chunked-last-crlf-missing + (progn + (goto-char url-http-chunked-last-crlf-missing) + (if (not (looking-at "\r\n")) + (url-http-debug + "Still spinning for the terminator of last chunk...") + (url-http-debug "Saw the last CRLF.") + (delete-region (match-beginning 0) (match-end 0)) + (when (url-http-parse-headers) + (url-http-activate-callback)))) + (save-excursion + (goto-char st) + (let ((read-next-chunk t) + (case-fold-search t) + (regexp nil) + (no-initial-crlf nil)) + ;; We need to loop thru looking for more chunks even within + ;; one after-change-function call. + (while read-next-chunk + (setq no-initial-crlf (= 0 url-http-chunked-counter)) + (if url-http-content-type + (url-display-percentage nil + "Reading [%s]... chunk #%d" + url-http-content-type url-http-chunked-counter) (url-display-percentage nil - "Reading [%s]... chunk #%d" - url-http-content-type url-http-chunked-counter) - (url-display-percentage nil - "Reading... chunk #%d" - url-http-chunked-counter)) - (url-http-debug "Reading chunk %d (%d %d %d)" - url-http-chunked-counter st nd length) - (setq regexp (if no-initial-crlf - "\\([0-9a-z]+\\).*\r?\n" - "\r?\n\\([0-9a-z]+\\).*\r?\n")) - - (if url-http-chunked-start - ;; We know how long the chunk is supposed to be, skip over - ;; leading crap if possible. - (if (> nd (+ url-http-chunked-start url-http-chunked-length)) - (progn - (url-http-debug "Got to the end of chunk #%d!" - url-http-chunked-counter) - (goto-char (+ url-http-chunked-start - url-http-chunked-length))) - (url-http-debug "Still need %d bytes to hit end of chunk" - (- (+ url-http-chunked-start - url-http-chunked-length) - nd)) - (setq read-next-chunk nil))) - (if (not read-next-chunk) - (url-http-debug "Still spinning for next chunk...") - (if no-initial-crlf (skip-chars-forward "\r\n")) - (if (not (looking-at regexp)) - (progn - ;; Must not have received the entirety of the chunk header, - ;; need to spin some more. - (url-http-debug "Did not see start of chunk @ %d!" (point)) - (setq read-next-chunk nil)) - ;; The data we got may have started in the middle of the - ;; initial chunk header, so move back to the start of the - ;; line and re-compute. - (when (= url-http-chunked-counter 0) - (beginning-of-line) - (looking-at regexp)) - (add-text-properties (match-beginning 0) (match-end 0) - (list 'chunked-encoding t - 'face 'cursor - 'invisible t)) - (setq url-http-chunked-length (string-to-number (buffer-substring - (match-beginning 1) - (match-end 1)) - 16) - url-http-chunked-counter (1+ url-http-chunked-counter) - url-http-chunked-start (set-marker - (or url-http-chunked-start - (make-marker)) - (match-end 0))) - (delete-region (match-beginning 0) (match-end 0)) - (url-http-debug "Saw start of chunk %d (length=%d, start=%d" - url-http-chunked-counter url-http-chunked-length - (marker-position url-http-chunked-start)) - (if (= 0 url-http-chunked-length) - (progn - ;; Found the end of the document! Wheee! - (url-http-debug "Saw end of stream chunk!") - (setq read-next-chunk nil) - (url-display-percentage nil nil) - ;; Every chunk, even the last 0-length one, is - ;; terminated by CRLF. Skip it. - (when (looking-at "\r?\n") - (url-http-debug "Removing terminator of last chunk") - (delete-region (match-beginning 0) (match-end 0))) - (if (re-search-forward "^\r?\n" nil t) - (url-http-debug "Saw end of trailers...")) - (if (url-http-parse-headers) - (url-http-activate-callback)))))))))) + "Reading... chunk #%d" + url-http-chunked-counter)) + (url-http-debug "Reading chunk %d (%d %d %d)" + url-http-chunked-counter st nd length) + (setq regexp (if no-initial-crlf + "\\([0-9a-z]+\\).*\r?\n" + "\r?\n\\([0-9a-z]+\\).*\r?\n")) + + (if url-http-chunked-start + ;; We know how long the chunk is supposed to be, skip over + ;; leading crap if possible. + (if (> nd (+ url-http-chunked-start url-http-chunked-length)) + (progn + (url-http-debug "Got to the end of chunk #%d!" + url-http-chunked-counter) + (goto-char (+ url-http-chunked-start + url-http-chunked-length))) + (url-http-debug "Still need %d bytes to hit end of chunk" + (- (+ url-http-chunked-start + url-http-chunked-length) + nd)) + (setq read-next-chunk nil))) + (if (not read-next-chunk) + (url-http-debug "Still spinning for next chunk...") + (if no-initial-crlf (skip-chars-forward "\r\n")) + (if (not (looking-at regexp)) + (progn + ;; Must not have received the entirety of the chunk header, + ;; need to spin some more. + (url-http-debug "Did not see start of chunk @ %d!" (point)) + (setq read-next-chunk nil)) + ;; The data we got may have started in the middle of the + ;; initial chunk header, so move back to the start of the + ;; line and re-compute. + (when (= url-http-chunked-counter 0) + (beginning-of-line) + (looking-at regexp)) + (add-text-properties (match-beginning 0) (match-end 0) + (list 'chunked-encoding t + 'face 'cursor + 'invisible t)) + (setq url-http-chunked-length + (string-to-number (buffer-substring (match-beginning 1) + (match-end 1)) + 16) + url-http-chunked-counter (1+ url-http-chunked-counter) + url-http-chunked-start (set-marker + (or url-http-chunked-start + (make-marker)) + (match-end 0))) + (delete-region (match-beginning 0) (match-end 0)) + (url-http-debug "Saw start of chunk %d (length=%d, start=%d" + url-http-chunked-counter url-http-chunked-length + (marker-position url-http-chunked-start)) + (if (= 0 url-http-chunked-length) + (progn + ;; Found the end of the document! Wheee! + (url-http-debug "Saw end of stream chunk!") + (setq read-next-chunk nil) + (url-display-percentage nil nil) + ;; Every chunk, even the last 0-length one, is + ;; terminated by CRLF. Skip it. + (if (not (looking-at "\r?\n")) + (progn + (url-http-debug + "Spinning for the terminator of last chunk...") + (setq url-http-chunked-last-crlf-missing + (point))) + (url-http-debug "Removing terminator of last chunk") + (delete-region (match-beginning 0) (match-end 0)) + (when (re-search-forward "^\r?\n" nil t) + (url-http-debug "Saw end of trailers...")) + (when (url-http-parse-headers) + (url-http-activate-callback)))))))))))) (defun url-http-wait-for-headers-change-function (_st nd _length) ;; This will wait for the headers to arrive and then splice in the @@ -1304,9 +1330,7 @@ The return value of this function is the retrieval buffer." (cl-check-type url url "Need a pre-parsed URL.") (let* (;; (host (url-host (or url-using-proxy url))) ;; (port (url-port (or url-using-proxy url))) - (nsm-noninteractive (or url-request-noninteractive - (and (boundp 'url-http-noninteractive) - url-http-noninteractive))) + (nsm-noninteractive (not (url-interactive-p))) ;; The following binding is needed in url-open-stream, which ;; is called from url-http-find-free-connection. (url-current-object url) @@ -1337,6 +1361,7 @@ The return value of this function is the retrieval buffer." url-http-after-change-function url-http-response-version url-http-response-status + url-http-chunked-last-crlf-missing url-http-chunked-length url-http-chunked-counter url-http-chunked-start @@ -1361,6 +1386,7 @@ The return value of this function is the retrieval buffer." url-http-noninteractive url-request-noninteractive url-http-data url-request-data url-http-process connection + url-http-chunked-last-crlf-missing nil url-http-chunked-length nil url-http-chunked-start nil url-http-chunked-counter 0 @@ -1407,10 +1433,10 @@ The return value of this function is the retrieval buffer." (and proxy-auth (concat "Proxy-Authorization: " proxy-auth "\r\n"))) "\r\n") - (url-host url-current-object) + (puny-encode-domain (url-host url-current-object)) (or (url-port url-current-object) url-https-default-port) - (url-host url-current-object)))) + (puny-encode-domain (url-host url-current-object))))) (defun url-https-proxy-after-change-function (_st _nd _length) (let* ((process-buffer (current-buffer)) @@ -1432,12 +1458,12 @@ The return value of this function is the retrieval buffer." (condition-case e (let ((tls-connection (gnutls-negotiate :process proc - :hostname (url-host url-current-object) + :hostname (puny-encode-domain (url-host url-current-object)) :verify-error nil))) ;; check certificate validity (setq tls-connection (nsm-verify-connection tls-connection - (url-host url-current-object) + (puny-encode-domain (url-host url-current-object)) (url-port url-current-object))) (with-current-buffer process-buffer (erase-buffer)) (set-process-buffer tls-connection process-buffer) diff --git a/lisp/url/url-privacy.el b/lisp/url/url-privacy.el index 78bb78b1ee2..f897248fe4c 100644 --- a/lisp/url/url-privacy.el +++ b/lisp/url/url-privacy.el @@ -48,6 +48,7 @@ (pcase (or window-system 'tty) ('x "X11") ('ns "OpenStep") + ('pgtk "PureGTK") ('tty "TTY") (_ nil))))) diff --git a/lisp/url/url-queue.el b/lisp/url/url-queue.el index 8741bca9423..b2e24607e11 100644 --- a/lisp/url/url-queue.el +++ b/lisp/url/url-queue.el @@ -31,6 +31,7 @@ (eval-when-compile (require 'cl-lib)) (require 'browse-url) (require 'url-parse) +(require 'url-file) (defcustom url-queue-parallel-processes 6 "The number of concurrent processes." @@ -155,14 +156,16 @@ The variable `url-queue-timeout' sets a timeout." (defun url-queue-start-retrieve (job) (setf (url-queue-buffer job) (ignore-errors - (with-current-buffer (if (buffer-live-p (url-queue-context-buffer job)) + (with-current-buffer (if (buffer-live-p + (url-queue-context-buffer job)) (url-queue-context-buffer job) (current-buffer)) - (let ((url-request-noninteractive t)) - (url-retrieve (url-queue-url job) - #'url-queue-callback-function (list job) - (url-queue-silentp job) - (url-queue-inhibit-cookiesp job))))))) + (let ((url-request-noninteractive t) + (url-allow-non-local-files t)) + (url-retrieve (url-queue-url job) + #'url-queue-callback-function (list job) + (url-queue-silentp job) + (url-queue-inhibit-cookiesp job))))))) (defun url-queue-prune-old-entries () (let (dead-jobs) diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index b8b7980e40b..fc84d451760 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el @@ -1,7 +1,6 @@ ;;; url-util.el --- Miscellaneous helper routines for URL library -*- lexical-binding: t -*- -;; Copyright (C) 1996-1999, 2001, 2004-2022 Free Software Foundation, -;; Inc. +;; Copyright (C) 1996-2022 Free Software Foundation, Inc. ;; Author: Bill Perry <wmperry@gnu.org> ;; Maintainer: emacs-devel@gnu.org @@ -217,9 +216,7 @@ Will not do anything if `url-show-status' is nil." ;;;###autoload (defun url-percentage (x y) - (if (fboundp 'float) - (round (* 100 (/ x (float y)))) - (/ (* x 100) y))) + (round (* 100 (/ x (float y))))) ;;;###autoload (defalias 'url-basepath 'url-file-directory) diff --git a/lisp/url/url-vars.el b/lisp/url/url-vars.el index 83c089a930a..1012525568b 100644 --- a/lisp/url/url-vars.el +++ b/lisp/url/url-vars.el @@ -1,7 +1,6 @@ ;;; url-vars.el --- Variables for Uniform Resource Locator tool -*- lexical-binding:t -*- -;; Copyright (C) 1996-1999, 2001, 2004-2022 Free Software Foundation, -;; Inc. +;; Copyright (C) 1996-2022 Free Software Foundation, Inc. ;; Keywords: comm, data, processes, hypermedia @@ -131,7 +130,7 @@ Samples: This variable controls several other variables and is _NOT_ automatically updated. Call the function `url-setup-privacy-info' after modifying this variable." - :initialize 'custom-initialize-default + :initialize #'custom-initialize-default :set (lambda (sym val) (set-default sym val) (url-setup-privacy-info)) :type '(radio (const :tag "None (you believe in the basic goodness of humanity)" :value none) @@ -204,10 +203,9 @@ from the ACCESS_proxy environment variables." :type 'boolean :group 'url-cache) -(defvar url-mime-separator-chars (mapcar 'identity - (concat "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789'()+_,-./=?")) +(defvar url-mime-separator-chars (append "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789'()+_,-./=?") "Characters allowable in a MIME multipart separator.") (defcustom url-bad-port-list @@ -254,7 +252,7 @@ Generated according to current coding system priorities." (push (car elt) accum))) (nreverse accum))))) (concat (format "%s;q=1, " (pop ordered)) - (mapconcat 'symbol-name ordered ";q=0.5, ") + (mapconcat #'symbol-name ordered ";q=0.5, ") ";q=0.5"))) (defvar url-mime-charset-string nil @@ -398,7 +396,7 @@ Should be one of: (defvar url-lazy-message-time 0) ;; Fixme: We may not be able to run SSL. -(defvar url-extensions-header "Security/Digest Security/SSL") +(defvar url-extensions-header nil) (defvar url-parse-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table) @@ -424,11 +422,15 @@ Should be one of: This should be set, e.g. by mail user agents rendering HTML to avoid `bugs' which call home.") +(defun url-interactive-p () + "Non-nil when the current request is from an interactive context." + (not (or url-request-noninteractive + (bound-and-true-p url-http-noninteractive)))) + ;; Obsolete (defconst url-version "Emacs" "Version number of URL package.") (make-obsolete-variable 'url-version 'emacs-version "28.1") (provide 'url-vars) - ;;; url-vars.el ends here |