From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 3 Apr 2022 14:24:24 -0700 Subject: [PATCH 03/35] Accept user keyword arg in ERC entry-point commands * lisp/erc/erc-backend.el (erc-server-reconnect): Reuse the username argument from the previous session's USER command when reconnecting. Also pass the existing client certificate, fixing an issue related to bug#47788. (erc-session-user-full-name): Move variable here from erc.el. (erc-session-username): Add new local variable to store entry point parameter. * lisp/erc/erc.el (erc-session-user-full-name): Move variable to erc-backend. (erc-open, erc-determine-parameters, erc, erc-tls): Accept new optional user parameter. (erc-query): Preserve current `erc-session-username' when calling `erc-open'. (erc-login): Use `erc-session-username' instead of deriving it. (erc-compute-user): Add new function to determine user name from explicit argument or user options. (Bug#54824) --- lisp/erc/erc-backend.el | 12 +++++++++++- lisp/erc/erc.el | 34 ++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index d442013cf4..8f271a7eb3 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -123,6 +123,14 @@ erc-server-current-nick "Nickname on the current server. Use `erc-current-nick' to access this.") +(defvar-local erc-session-user-full-name nil + "Real name used for the current session. +Sent as the last argument to the USER command.") + +(defvar-local erc-session-username nil + "Username used for the current session. +Sent as the first argument of the USER command.") + ;;; Server attributes (defvar-local erc-server-process nil @@ -585,7 +593,9 @@ erc-server-reconnect (let ((erc-server-connect-function (or erc-session-connector #'erc-open-network-stream))) (erc-open erc-session-server erc-session-port erc-server-current-nick - erc-session-user-full-name t erc-session-password))))) + erc-session-user-full-name t erc-session-password + nil nil nil erc-session-client-certificate + erc-session-username))))) (defun erc-server-delayed-reconnect (buffer) (if (buffer-live-p buffer) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 9240791b1e..1a6911a511 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -149,6 +149,8 @@ erc-session-client-certificate (defvar erc-session-connector) (defvar erc-session-port) (defvar erc-session-server) +(defvar erc-session-user-full-name) +(defvar erc-session-username) ;; tunable connection and authentication parameters @@ -1820,9 +1822,6 @@ erc-buffer-list-with-nick (defvar-local erc-default-recipients nil "List of default recipients of the current buffer.") -(defvar-local erc-session-user-full-name nil - "Full name of the user on the current server.") - (defvar-local erc-channel-user-limit nil "Limit of users per channel.") @@ -1989,8 +1988,8 @@ erc-setup-buffer (defun erc-open (&optional server port nick full-name connect passwd tgt-list channel process - client-certificate) - "Connect to SERVER on PORT as NICK with FULL-NAME. + client-certificate user) + "Connect to SERVER on PORT as NICK with USER and FULL-NAME. If CONNECT is non-nil, connect to the server. Otherwise assume already connected and just create a separate buffer for the new @@ -2095,7 +2094,7 @@ erc-open (erc-display-prompt) (goto-char (point-max))) - (erc-determine-parameters server port nick full-name) + (erc-determine-parameters server port nick full-name user) ;; Saving log file on exit (run-hook-with-args 'erc-connect-pre-hook buffer) @@ -2216,6 +2215,7 @@ erc-select-read-args (cl-defun erc (&key (server (erc-compute-server)) (port (erc-compute-port)) (nick (erc-compute-nick)) + (user (erc-compute-user)) password (full-name (erc-compute-full-name))) "ERC is a powerful, modular, and extensible IRC client. @@ -2227,6 +2227,7 @@ erc (server (erc-compute-server)) (port (erc-compute-port)) (nick (erc-compute-nick)) + (user (erc-compute-user)) password (full-name (erc-compute-full-name)) @@ -2238,7 +2239,7 @@ erc whereas `erc-compute-port' and `erc-compute-nick' will be invoked for the values of the other parameters." (interactive (erc-select-read-args)) - (erc-open server port nick full-name t password)) + (erc-open server port nick full-name t password nil nil nil nil user)) ;;;###autoload (defalias 'erc-select #'erc) @@ -2248,6 +2249,7 @@ 'erc-ssl (cl-defun erc-tls (&key (server (erc-compute-server)) (port (erc-compute-port)) (nick (erc-compute-nick)) + (user (erc-compute-user)) password (full-name (erc-compute-full-name)) client-certificate) @@ -2291,7 +2293,7 @@ erc-tls (erc-select-read-args))) (let ((erc-server-connect-function 'erc-open-tls-stream)) (erc-open server port nick full-name t password - nil nil nil client-certificate))) + nil nil nil client-certificate user))) (defun erc-open-tls-stream (name buffer host port &rest parameters) "Open an TLS stream to an IRC server. @@ -4311,7 +4313,8 @@ erc-query nil (list target) target - erc-server-process))) + erc-server-process + erc-session-username))) (unless buf (error "Couldn't open query window")) (erc-update-mode-line) @@ -6153,14 +6156,14 @@ erc-login (erc-server-send (format "USER %s %s %s :%s" ;; hacked - S.B. - (if erc-anonymous-login erc-email-userid (user-login-name)) + erc-session-username "0" "*" erc-session-user-full-name)) (erc-update-mode-line)) ;; connection properties' heuristics -(defun erc-determine-parameters (&optional server port nick name) +(defun erc-determine-parameters (&optional server port nick name user) "Determine the connection and authentication parameters. Sets the buffer local variables: @@ -6168,11 +6171,13 @@ erc-determine-parameters - `erc-session-server' - `erc-session-port' - `erc-session-user-full-name' +- `erc-session-username' - `erc-server-current-nick'" (setq erc-session-connector erc-server-connect-function erc-session-server (erc-compute-server server) erc-session-port (or port erc-default-port) - erc-session-user-full-name (erc-compute-full-name name)) + erc-session-user-full-name (erc-compute-full-name name) + erc-session-username (erc-compute-user user)) (erc-set-current-nick (erc-compute-nick nick))) (defun erc-compute-server (&optional server) @@ -6190,6 +6195,10 @@ erc-compute-server (getenv "IRCSERVER") erc-default-server)) +(defun erc-compute-user (&optional user) + "Return a suitable value for the session user name." + (or user (if erc-anonymous-login erc-email-userid (user-login-name)))) + (defun erc-compute-nick (&optional nick) "Return user's IRC nick. @@ -7018,6 +7027,7 @@ erc-get-parsed-vector-type ;; Teach url.el how to open irc:// URLs with ERC. ;; To activate, customize `url-irc-function' to `url-irc-erc'. +;; FIXME change user to nick, and use API to find server buffer ;;;###autoload (defun erc-handle-irc-url (host port channel user password) "Use ERC to IRC on HOST:PORT in CHANNEL as USER with PASSWORD. -- 2.36.1