From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args Date: Sun, 01 Jan 2023 17:41:12 -0800 Message-ID: <87h6x9yapz.fsf__20251.8793450267$1672623749$gmane$org@neverwas.me> References: <87mt750ygt.fsf@neverwas.me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35448"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-erc@gnu.org To: 60428@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 02 02:42:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pC9qG-0008yy-Id for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Jan 2023 02:42:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pC9q3-0001jm-Ez; Sun, 01 Jan 2023 20:42:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pC9py-0001jY-AI for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 20:42:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pC9py-0007a5-1b for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 20:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pC9px-0000Fl-Jl for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 20:42:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jan 2023 01:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60428 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 60428-submit@debbugs.gnu.org id=B60428.1672623690933 (code B ref 60428); Mon, 02 Jan 2023 01:42:01 +0000 Original-Received: (at 60428) by debbugs.gnu.org; 2 Jan 2023 01:41:30 +0000 Original-Received: from localhost ([127.0.0.1]:42130 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC9pQ-0000Ex-8V for submit@debbugs.gnu.org; Sun, 01 Jan 2023 20:41:29 -0500 Original-Received: from mail-108-mta126.mxroute.com ([136.175.108.126]:35207) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pC9pN-0000Ei-BN for 60428@debbugs.gnu.org; Sun, 01 Jan 2023 20:41:27 -0500 Original-Received: from mail-111-mta2.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta126.mxroute.com (ZoneMTA) with ESMTPSA id 1857023da88000011e.001 for <60428@debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Mon, 02 Jan 2023 01:41:16 +0000 X-Zone-Loop: 5cde850f9389adbad2b62953cbcdf8066fbdd70175c6 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=neverwas.me ; s=x; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=jR38OA/hEboYirlO+bGnpWMyttWOMcssP3C7d+l1xis=; b=mwy0hRYY8Clzw6HgrjnBb0t1Vk q/ufDJyznl8YJfE4BBNVpGEIsAI67HXFFV2SA3R5HWaT3y3/pttoALA9tn0bVKlpRH92jcBefsGRr c5DY28PiMcKZGlii9tGZbYegZWy1yS37vnxVrSIL+/7CCKKcDU33/t3mSyQqcp4I15K+qNizCNAGY ftDV+zCUIAkHqWjH7ybMwvsU5P+W7WQUYCUDQBGQmNKg14k2iqsTf5R2ip+FGNciDxn7ZB/CaO5gD e4OjvLKwe3uMzz1ZAQWr4DN1TbQRttOGoNByv4E0wRf5fc6IPP2VYOn4/gJL240q79ynJTkih9jTR rGx/mx8A==; In-Reply-To: <87mt750ygt.fsf@neverwas.me> (J. P.'s message of "Fri, 30 Dec 2022 06:15:30 -0800") X-Authenticated-Id: masked@neverwas.me X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:252303 Archived-At: --=-=-= Content-Type: text/plain v2. Respect `erc-prompt-for-password'. Remove `run-at-time' hack from regression fix. "J.P." writes: > The proposed patch abandons most of the envisioned niceties and > instead employs a hack to just force a non-local exit and schedule a > call to `erc-tls' when appropriate. It also instructs users to do that > themselves in the future (issue an M-x erc-tls, that is). Hopefully, > this makes for an acceptable compromise. I've forsaken the first part out of an abundance of caution. So this now just prints a warning and proceeds with a non-TLS connection. If anyone finds that unsatisfactory, please say something. > BTW, a POC patch set far more faithful to the original breadth of the > feature (and way less hacky) is also attached. Perhaps it'll inform > further exploration in this area down the road (but not for Emacs 29). IOW, the de facto goal here is to make interactive `erc' a "universal" entry point for both plain and TLS connections. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0000-v1-v2.diff >From 448686bf96105833cd3e3ee319118c1672d95ca0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 1 Jan 2023 17:36:36 -0800 Subject: [PATCH 0/4] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (4): Fix default-port regression in erc-select-read-args [5.6] Be smarter about switching to TLS from M-x erc [5.6] Add display option for interactive ERC invocations [5.6] Optionally prompt for more ERC entry-point params doc/misc/erc.texi | 2 +- lisp/erc/erc.el | 87 +++++++++++++++++++++++++++++--------- test/lisp/erc/erc-tests.el | 66 +++++++++++++++++++++-------- 3 files changed, 118 insertions(+), 37 deletions(-) Interdiff: diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 2fcdb513b5d..7f2dd89342b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1486,7 +1486,8 @@ erc-interactive-display possible values." :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA :group 'erc-buffers - :type '(choice (const :tag "Split window and select" window) + :type '(choice (const :tag "Use value of `erc-join-buffer'" nil) + (const :tag "Split window and select" window) (const :tag "Split window, don't select" window-noselect) (const :tag "New frame" frame) (const :tag "Bury new and don't display existing" bury) @@ -2180,7 +2181,7 @@ erc-select-read-args With prefix arg, also prompt for user and full name." (require 'url-parse) (let* ((input (let ((d (erc-compute-server))) - (read-string (format "Server (default is %S): " d) + (read-string (format "Server or URL (default is %S): " d) nil 'erc-server-history-list d))) ;; For legacy reasons, also accept a URL without a scheme. (url (url-generic-parse-url (erc--ensure-url input))) @@ -2199,34 +2200,33 @@ erc-select-read-args (read-string (format "Nickname (default is %S): " d) nil 'erc-nick-history-list d)))) (user (and current-prefix-arg - (let ((d (or (url-user url) (erc-compute-user)))) + (let ((d (erc-compute-user (url-user url)))) (read-string (format "User (default is %S): " d) nil nil d)))) (full (and current-prefix-arg - (let ((d (or (url-user url) (erc-compute-full-name)))) + (let ((d (erc-compute-full-name (url-user url)))) (read-string (format "Full name (default is %S): " d) nil nil d)))) - (passwd (or (url-password url) - (let* - ((p (with-suppressed-warnings - ((obsolete erc-password)) - erc-password)) - (m (if p - (format "Server password (default is %S): " p) - "Server password (optional): "))) - (if erc-prompt-for-password (read-passwd m nil p) p)))) - (opener erc-server-connect-function)) + (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) + (or (url-password url) erc-password))) + (m (if p + (format "Server password (default is %S): " p) + "Server password (optional): "))) + (if erc-prompt-for-password (read-passwd m nil p) p))) + (opener (and (or sp (eql port erc-default-port-tls) + (and (equal server erc-default-server) + (not (string-prefix-p "irc://" input)) + (eql port erc-default-port) + (y-or-n-p "Connect using TLS instead? ") + (setq port erc-default-port-tls))) + #'erc-open-tls-stream))) (when (and passwd (string= "" passwd)) (setq passwd nil)) - (when (and (equal server erc-default-server) - (not (string-prefix-p "irc://" input)) - (or (not (eql port erc-default-port)) - (and (y-or-n-p "Connect using TLS instead? ") - (setq port erc-default-port-tls)))) - (setq opener #'erc-open-tls-stream)) `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user)) ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full)) - buffer-display ,erc-interactive-display connect-function ,opener))) + ,@(and erc-interactive-display + `(buffer-display ,erc-interactive-display)) + ,@(and opener `(connect-function ,opener))))) ;;;###autoload @@ -2238,8 +2238,7 @@ erc (full-name (erc-compute-full-name)) id ;; For interactive use - ((buffer-display erc-buffer-display) - erc-buffer-display) + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) erc-server-connect-function)) "ERC is a powerful, modular, and extensible IRC client. @@ -2284,10 +2283,12 @@ erc-tls client-certificate id ;; For interactive use - ((buffer-display erc-buffer-display) - erc-buffer-display) + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) - #'erc-open-tls-stream)) + (if (eq erc-server-connect-function + #'erc-open-network-stream) + #'erc-open-tls-stream + erc-server-connect-function))) "ERC is a powerful, modular, and extensible IRC client. This function is the main entry point for ERC over TLS. @@ -2334,12 +2335,7 @@ erc-tls interactively. \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)" - (interactive (let ((erc-server-connect-function - (if (eq erc-server-connect-function - #'erc-open-network-stream) - #'erc-open-tls-stream - erc-server-connect-function)) - (erc-port (or erc-port erc-default-port-tls))) + (interactive (let ((erc-default-port erc-default-port-tls)) (erc-select-read-args))) (progn (erc-open server port nick full-name t password diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 9d09df44883..d05b0efe2ed 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1001,7 +1001,7 @@ erc--server-connect-dumb-ipv6-regexp (ert-deftest erc-select-read-args () - (ert-info ("Doesn't default to TLS") + (ert-info ("Prompts for switch to TLS by default") (should (equal (ert-simulate-keys "\r\r\r\ry\r" (erc-select-read-args)) (list :server "irc.libera.chat" @@ -1010,44 +1010,58 @@ erc-select-read-args 'buffer-display 'buffer 'connect-function #'erc-open-tls-stream)))) + (ert-info ("Switches to TLS when port matches default TLS port") + (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'buffer-display 'buffer + 'connect-function #'erc-open-tls-stream)))) + + (ert-info ("Switches to TLS when URL is ircs://") + (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'buffer-display 'buffer + 'connect-function #'erc-open-tls-stream)))) + + (setq-local erc-interactive-display nil) ; cheat to save space + (ert-info ("Opt out of non-TLS warning manually") (should (equal (ert-simulate-keys "\r\r\r\rn\r" (erc-select-read-args)) (list :server "irc.libera.chat" :port 6667 - :nick (user-login-name) - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick (user-login-name))))) - (ert-info ("Override non-TLS warning via URL scheme") + (ert-info ("Override default TLS") (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r" (erc-select-read-args)) (list :server "irc.libera.chat" :port 6667 - :nick (user-login-name) - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick (user-login-name))))) (ert-info ("Address includes port") (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r" (erc-select-read-args)) (list :server "localhost" :port 6667 - :nick "nick" - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick "nick")))) (ert-info ("Address includes nick, password skipped via option") (should (equal (ert-simulate-keys "nick@localhost:6667\r" (let (erc-prompt-for-password) - (butlast (erc-select-read-args) 4))) + (erc-select-read-args))) (list :server "localhost" :port 6667 :nick "nick")))) (ert-info ("Address includes nick and password") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r" - (butlast (erc-select-read-args) 4)) + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r" + (erc-select-read-args)) (list :server "localhost" :port 6667 :nick "nick" @@ -1055,29 +1069,29 @@ erc-select-read-args (ert-info ("IPv6 address plain") (should (equal (ert-simulate-keys "::1\r\r\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick (user-login-name))))) (ert-info ("IPv6 address with port") (should (equal (ert-simulate-keys "[::1]:6667\r\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick (user-login-name))))) (ert-info ("IPv6 address includes nick") (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick "nick")))) (ert-info ("Extra args use URL nick by default") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r" + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r" (let ((current-prefix-arg '(4))) - (butlast (erc-select-read-args) 4))) + (erc-select-read-args))) (list :server "localhost" :port 6667 :nick "nick" -- 2.38.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-default-port-regression-in-erc-select-read-args.patch >From 574671c8bdc1cb5a56b0c4ffe0f35be9fa0161f7 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 1/4] Fix default-port regression in erc-select-read-args * lisp/erc/erc.el (erc--warn-unencrypted): New function, likely temporary, to warn new users connecting interactively to the default server, "irc.libara.chat", via the default non-TLS port, 6667. (erc-select-read-args): Remove stray code from incomplete feature introduced by bug#56514. Ensure connecting always works with default port, which is non-TLS. Respect `erc-prompt-for-password' when user pastes URL containing password component into "server" prompt. Maybe add `erc--warn-unencrypted' as one-off hook for impending connection. * test/lisp/erc/erc-tests.el (erc-select-read-args): Always expect password prompt and sometimes a non-TLS port when `erc' called interactively. (Bug#60428.) --- lisp/erc/erc.el | 38 +++++++++++++++++++++++++++++--------- test/lisp/erc/erc-tests.el | 6 +++--- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index fe1201dd3a8..6315d5aa482 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2161,6 +2161,23 @@ erc--ensure-url (setq input (concat "irc://" input))) input) +;; A temporary means of addressing the problem of ERC's namesake entry +;; point defaulting to a non-TLS connection with its default server +;; (bug#60428). +(defun erc--warn-unencrypted () + ;; Remove unconditionally to avoid wrong context due to races from + ;; simultaneous dialing or aborting (e.g., via `keybaord-quit'). + (remove-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted) + (when (and (process-contact erc-server-process :nowait) + (equal erc-session-server erc-default-server) + (eql erc-session-port erc-default-port)) + ;; FIXME use the autoloaded `info' instead of `Info-goto-node' in + ;; `erc-button-alist'. + (require 'info nil t) + (erc-display-error-notice + nil (concat "This connection is unencrypted. Please use `erc-tls'" + " from now on. See Info:\"(erc) connecting\" for more.")))) + ;;;###autoload (defun erc-select-read-args () "Prompt the user for values of nick, server, port, and password." @@ -2171,10 +2188,7 @@ erc-select-read-args ;; For legacy reasons, also accept a URL without a scheme. (url (url-generic-parse-url (erc--ensure-url input))) (server (url-host url)) - (sp (and (or (string-suffix-p "s" (url-type url)) - (and (equal server erc-default-server) - (not (string-prefix-p "irc://" input)))) - 'ircs-u)) + (sp (and (string-suffix-p "s" (url-type url)) erc-default-port-tls)) (port (or (url-portspec url) (erc-compute-port (let ((d (erc-compute-port sp))) ; may be a string @@ -2187,13 +2201,19 @@ erc-select-read-args (let ((d (erc-compute-nick))) (read-string (format "Nickname (default is %S): " d) nil 'erc-nick-history-list d)))) - (passwd (or (url-password url) - (if erc-prompt-for-password - (read-passwd "Server password (optional): ") - (with-suppressed-warnings ((obsolete erc-password)) - erc-password))))) + (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) + (or (url-password url) erc-password))) + (m (if p + (format "Server password (default is %S): " p) + "Server password (optional): "))) + (if erc-prompt-for-password (read-passwd m nil p) p)))) (when (and passwd (string= "" passwd)) (setq passwd nil)) + (when (and (equal server erc-default-server) + (eql port erc-default-port) + (not (eql port erc-default-port-tls)) ; not `erc-tls' + (not (string-prefix-p "irc://" input))) ; not yanked URL + (add-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted)) (list :server server :port port :nick nick :password passwd))) ;;;###autoload diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 6807b24bfc6..85506c3d27e 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1001,11 +1001,11 @@ erc--server-connect-dumb-ipv6-regexp (ert-deftest erc-select-read-args () - (ert-info ("Defaults to TLS") + (ert-info ("Does not default to TLS") (should (equal (ert-simulate-keys "\r\r\r\r" (erc-select-read-args)) (list :server "irc.libera.chat" - :port 6697 + :port 6667 :nick (user-login-name) :password nil)))) @@ -1036,7 +1036,7 @@ erc-select-read-args :password nil)))) (ert-info ("Address includes nick and password") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r" + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r" (erc-select-read-args)) (list :server "localhost" :port 6667 -- 2.38.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-5.6-Be-smarter-about-switching-to-TLS-from-M-x-erc.patch >From 7a8659ed2132858e5c52cf09c9050cc00463607f Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 2/4] [5.6] Be smarter about switching to TLS from M-x erc * lisp/erc/erc.el (erc--warn-unencrypted): Remove newly unused internal function. (erc-select-read-args): Offer to use TLS when user runs M-x erc and opts for default server and port or provides the well-known IANA TLS port or enters an ircs:// URL at the server prompt. For the last two, do this immediately instead of calling `erc-tls' interactively and imposing a review of just-chosen values. Also remove error warnings and ensure `erc-tls' still works by setting `erc-server-connect-function' to `erc-open-tls-stream' when appropriate. Include the word "URL" in server prompt. (erc, erc-tls): Add internal keyword arguments for interactive use, but don't make them colon-prefixed, i.e., `keywordp'. * test/lisp/erc/erc-tests.el (erc-select-read-args): Modify return values to expect additional `connect-function' keyword argument. (Bug#60428.) --- lisp/erc/erc.el | 61 +++++++++++++++++++------------------- test/lisp/erc/erc-tests.el | 52 +++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 48 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 6315d5aa482..96866432ebd 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2161,29 +2161,12 @@ erc--ensure-url (setq input (concat "irc://" input))) input) -;; A temporary means of addressing the problem of ERC's namesake entry -;; point defaulting to a non-TLS connection with its default server -;; (bug#60428). -(defun erc--warn-unencrypted () - ;; Remove unconditionally to avoid wrong context due to races from - ;; simultaneous dialing or aborting (e.g., via `keybaord-quit'). - (remove-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted) - (when (and (process-contact erc-server-process :nowait) - (equal erc-session-server erc-default-server) - (eql erc-session-port erc-default-port)) - ;; FIXME use the autoloaded `info' instead of `Info-goto-node' in - ;; `erc-button-alist'. - (require 'info nil t) - (erc-display-error-notice - nil (concat "This connection is unencrypted. Please use `erc-tls'" - " from now on. See Info:\"(erc) connecting\" for more.")))) - ;;;###autoload (defun erc-select-read-args () "Prompt the user for values of nick, server, port, and password." (require 'url-parse) (let* ((input (let ((d (erc-compute-server))) - (read-string (format "Server (default is %S): " d) + (read-string (format "Server or URL (default is %S): " d) nil 'erc-server-history-list d))) ;; For legacy reasons, also accept a URL without a scheme. (url (url-generic-parse-url (erc--ensure-url input))) @@ -2206,15 +2189,20 @@ erc-select-read-args (m (if p (format "Server password (default is %S): " p) "Server password (optional): "))) - (if erc-prompt-for-password (read-passwd m nil p) p)))) + (if erc-prompt-for-password (read-passwd m nil p) p))) + (opener (and (or sp (eql port erc-default-port-tls) + (and (equal server erc-default-server) + (not (string-prefix-p "irc://" input)) + (eql port erc-default-port) + (y-or-n-p "Connect using TLS instead? ") + (setq port erc-default-port-tls))) + #'erc-open-tls-stream))) (when (and passwd (string= "" passwd)) (setq passwd nil)) - (when (and (equal server erc-default-server) - (eql port erc-default-port) - (not (eql port erc-default-port-tls)) ; not `erc-tls' - (not (string-prefix-p "irc://" input))) ; not yanked URL - (add-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted)) - (list :server server :port port :nick nick :password passwd))) + `( :server ,server :port ,port :nick ,nick + ,@(and passwd `(:password ,passwd)) + ,@(and opener `(connect-function ,opener))))) + ;;;###autoload (cl-defun erc (&key (server (erc-compute-server)) @@ -2223,7 +2211,10 @@ erc (user (erc-compute-user)) password (full-name (erc-compute-full-name)) - id) + id + ;; For interactive use + ((connect-function erc-server-connect-function) + erc-server-connect-function)) "ERC is a powerful, modular, and extensible IRC client. This function is the main entry point for ERC. @@ -2246,7 +2237,9 @@ erc whereas `erc-compute-port' and `erc-compute-nick' will be invoked for the values of the other parameters. -See `erc-tls' for the meaning of ID." +See `erc-tls' for the meaning of ID. + +\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME ID)" (interactive (erc-select-read-args)) (erc-open server port nick full-name t password nil nil nil nil user id)) @@ -2262,7 +2255,13 @@ erc-tls password (full-name (erc-compute-full-name)) client-certificate - id) + id + ;; For interactive use + ((connect-function erc-server-connect-function) + (if (eq erc-server-connect-function + #'erc-open-network-stream) + #'erc-open-tls-stream + erc-server-connect-function))) "ERC is a powerful, modular, and extensible IRC client. This function is the main entry point for ERC over TLS. @@ -2306,10 +2305,12 @@ erc-tls the server buffer and identifying the connection unequivocally. See info node `(erc) Network Identifier' for details. Like USER and CLIENT-CERTIFICATE, this parameter cannot be specified -interactively." +interactively. + +\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)" (interactive (let ((erc-default-port erc-default-port-tls)) (erc-select-read-args))) - (let ((erc-server-connect-function 'erc-open-tls-stream)) + (progn (erc-open server port nick full-name t password nil nil nil client-certificate user id))) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 85506c3d27e..10adc9d53a7 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1001,30 +1001,50 @@ erc--server-connect-dumb-ipv6-regexp (ert-deftest erc-select-read-args () - (ert-info ("Does not default to TLS") - (should (equal (ert-simulate-keys "\r\r\r\r" + (ert-info ("Prompts for switch to TLS by default") + (should (equal (ert-simulate-keys "\r\r\r\ry\r" (erc-select-read-args)) (list :server "irc.libera.chat" - :port 6667 + :port 6697 :nick (user-login-name) - :password nil)))) + 'connect-function #'erc-open-tls-stream)))) + + (ert-info ("Switches to TLS when port matches default TLS port") + (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'connect-function #'erc-open-tls-stream)))) + + (ert-info ("Switches to TLS when URL is ircs://") + (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'connect-function #'erc-open-tls-stream)))) + + (ert-info ("Opt out of non-TLS warning manually") + (should (equal (ert-simulate-keys "\r\r\r\rn\r" + (erc-select-read-args)) + (list :server "irc.libera.chat" + :port 6667 + :nick (user-login-name))))) (ert-info ("Override default TLS") (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r" (erc-select-read-args)) (list :server "irc.libera.chat" :port 6667 - :nick (user-login-name) - :password nil)))) + :nick (user-login-name))))) (ert-info ("Address includes port") - (should (equal (ert-simulate-keys - "localhost:6667\rnick\r\r" + (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r" (erc-select-read-args)) (list :server "localhost" :port 6667 - :nick "nick" - :password nil)))) + :nick "nick")))) (ert-info ("Address includes nick, password skipped via option") (should (equal (ert-simulate-keys "nick@localhost:6667\r" @@ -1032,8 +1052,7 @@ erc-select-read-args (erc-select-read-args))) (list :server "localhost" :port 6667 - :nick "nick" - :password nil)))) + :nick "nick")))) (ert-info ("Address includes nick and password") (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r" @@ -1048,24 +1067,21 @@ erc-select-read-args (erc-select-read-args)) (list :server "[::1]" :port 6667 - :nick (user-login-name) - :password nil)))) + :nick (user-login-name))))) (ert-info ("IPv6 address with port") (should (equal (ert-simulate-keys "[::1]:6667\r\r\r" (erc-select-read-args)) (list :server "[::1]" :port 6667 - :nick (user-login-name) - :password nil)))) + :nick (user-login-name))))) (ert-info ("IPv6 address includes nick") (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r" (erc-select-read-args)) (list :server "[::1]" :port 6667 - :nick "nick" - :password nil))))) + :nick "nick"))))) (ert-deftest erc-tls () (let (calls) -- 2.38.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-5.6-Add-display-option-for-interactive-ERC-invocatio.patch >From 5afc6f4d40af031258bcda8fe440448ce8a1aa01 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 3/4] [5.6] Add display option for interactive ERC invocations * lisp/erc/erc.el (erc-buffer-display, erc-receive-query-display): Add aliases for `erc-join-buffer' and `erc-auto-query'. (erc-interactive-display): Add new option to control display of server buffers during interactive entry-point invocations. (erc-select-read-args): Pass `erc-interactive-display' to entry points. (erc, erc-tls): Add interactive-only to control initial buffer display. * test/lisp/erc/erc-tests.el (erc-select-read-args): Expect buffer-display values from `erc-interactive-display'. (Bug#60428.) --- lisp/erc/erc.el | 19 +++++++++++++++++++ test/lisp/erc/erc-tests.el | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 96866432ebd..09d55f60990 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1459,6 +1459,7 @@ erc-default-port-tls "IRC port to use for encrypted connections if it cannot be \ detected otherwise.") +(defvaralias 'erc-buffer-display 'erc-join-buffer) (defcustom erc-join-buffer 'bury "Determines how to display a newly created IRC buffer. @@ -1479,6 +1480,19 @@ erc-join-buffer (const :tag "Use current buffer" buffer) (const :tag "Use current buffer" t))) +(defcustom erc-interactive-display 'buffer + "How and whether to display server buffers for M-x erc. +See `erc-buffer-display' and friends for a description of +possible values." + :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA + :group 'erc-buffers + :type '(choice (const :tag "Use value of `erc-join-buffer'" nil) + (const :tag "Split window and select" window) + (const :tag "Split window, don't select" window-noselect) + (const :tag "New frame" frame) + (const :tag "Bury new and don't display existing" bury) + (const :tag "Use current buffer" buffer))) + (defcustom erc-reconnect-display nil "How (and whether) to display a channel buffer upon reconnecting. @@ -2201,6 +2215,8 @@ erc-select-read-args (setq passwd nil)) `( :server ,server :port ,port :nick ,nick ,@(and passwd `(:password ,passwd)) + ,@(and erc-interactive-display + `(buffer-display ,erc-interactive-display)) ,@(and opener `(connect-function ,opener))))) @@ -2213,6 +2229,7 @@ erc (full-name (erc-compute-full-name)) id ;; For interactive use + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) erc-server-connect-function)) "ERC is a powerful, modular, and extensible IRC client. @@ -2257,6 +2274,7 @@ erc-tls client-certificate id ;; For interactive use + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) (if (eq erc-server-connect-function #'erc-open-network-stream) @@ -4492,6 +4510,7 @@ erc-query (with-current-buffer server-buffer (erc--open-target target))) +(defvaralias 'erc-receive-query-display 'erc-auto-query) (defcustom erc-auto-query 'window-noselect "If non-nil, create a query buffer each time you receive a private message. If the buffer doesn't already exist, it is created. diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 10adc9d53a7..91cdf2f1770 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1007,6 +1007,7 @@ erc-select-read-args (list :server "irc.libera.chat" :port 6697 :nick (user-login-name) + 'buffer-display 'buffer 'connect-function #'erc-open-tls-stream)))) (ert-info ("Switches to TLS when port matches default TLS port") @@ -1015,6 +1016,7 @@ erc-select-read-args (list :server "irc.gnu.org" :port 6697 :nick (user-login-name) + 'buffer-display 'buffer 'connect-function #'erc-open-tls-stream)))) (ert-info ("Switches to TLS when URL is ircs://") @@ -1023,8 +1025,11 @@ erc-select-read-args (list :server "irc.gnu.org" :port 6697 :nick (user-login-name) + 'buffer-display 'buffer 'connect-function #'erc-open-tls-stream)))) + (setq-local erc-interactive-display nil) ; cheat to save space + (ert-info ("Opt out of non-TLS warning manually") (should (equal (ert-simulate-keys "\r\r\r\rn\r" (erc-select-read-args)) -- 2.38.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0004-5.6-Optionally-prompt-for-more-ERC-entry-point-param.patch >From 448686bf96105833cd3e3ee319118c1672d95ca0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 4/4] [5.6] Optionally prompt for more ERC entry-point params * doc/misc/erc.texi: Update statement about availability of user param when entry points called interactively. * lisp/erc/erc.el (erc-select-read-args): Allow optionally calling entry points with a prefix arg to access params `user' and `:full-name'. (erc-tls): Update doc string. * test/lisp/erc/erc-tests.el (erc-select-read-args): Add test for extra args. (Bug#60428.) --- doc/misc/erc.texi | 2 +- lisp/erc/erc.el | 19 ++++++++++++++----- test/lisp/erc/erc-tests.el | 13 ++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi index 23cdcbff575..40ecd00b226 100644 --- a/doc/misc/erc.texi +++ b/doc/misc/erc.texi @@ -932,7 +932,7 @@ SASL your @samp{NickServ} password. To make this work, customize @code{erc-sasl-user} and @code{erc-sasl-password} or specify the @code{:user} and @code{:password} keyword arguments when invoking -@code{erc-tls}. Note that @code{:user} cannot be given interactively. +@code{erc-tls}. @item @code{external} (via Client TLS Certificate) This works in conjunction with the @code{:client-certificate} keyword diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 09d55f60990..7f2dd89342b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2177,7 +2177,8 @@ erc--ensure-url ;;;###autoload (defun erc-select-read-args () - "Prompt the user for values of nick, server, port, and password." + "Prompt the user for values of nick, server, port, and password. +With prefix arg, also prompt for user and full name." (require 'url-parse) (let* ((input (let ((d (erc-compute-server))) (read-string (format "Server or URL (default is %S): " d) @@ -2198,6 +2199,14 @@ erc-select-read-args (let ((d (erc-compute-nick))) (read-string (format "Nickname (default is %S): " d) nil 'erc-nick-history-list d)))) + (user (and current-prefix-arg + (let ((d (erc-compute-user (url-user url)))) + (read-string (format "User (default is %S): " d) + nil nil d)))) + (full (and current-prefix-arg + (let ((d (erc-compute-full-name (url-user url)))) + (read-string (format "Full name (default is %S): " d) + nil nil d)))) (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) (or (url-password url) erc-password))) (m (if p @@ -2213,8 +2222,8 @@ erc-select-read-args #'erc-open-tls-stream))) (when (and passwd (string= "" passwd)) (setq passwd nil)) - `( :server ,server :port ,port :nick ,nick - ,@(and passwd `(:password ,passwd)) + `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user)) + ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full)) ,@(and erc-interactive-display `(buffer-display ,erc-interactive-display)) ,@(and opener `(connect-function ,opener))))) @@ -2321,8 +2330,8 @@ erc-tls When present, ID should be a symbol or a string to use for naming the server buffer and identifying the connection unequivocally. -See info node `(erc) Network Identifier' for details. Like USER -and CLIENT-CERTIFICATE, this parameter cannot be specified +See info node `(erc) Network Identifier' for details. Like +CLIENT-CERTIFICATE, this parameter cannot be specified interactively. \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)" diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 91cdf2f1770..d05b0efe2ed 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1086,7 +1086,18 @@ erc-select-read-args (erc-select-read-args)) (list :server "[::1]" :port 6667 - :nick "nick"))))) + :nick "nick")))) + + (ert-info ("Extra args use URL nick by default") + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r" + (let ((current-prefix-arg '(4))) + (erc-select-read-args))) + (list :server "localhost" + :port 6667 + :nick "nick" + :user "nick" + :password "sesame" + :full-name "nick"))))) (ert-deftest erc-tls () (let (calls) -- 2.38.1 --=-=-=--