From: Vibhav Pant <vibhavp@gmail.com>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [PATCH] Add option to ERC to make all connections use SSL.
Date: Sat, 2 Aug 2014 23:17:13 +0530 [thread overview]
Message-ID: <CA+T2Sh0tdaEPZ_REyet435sM+wTDbznoT5qdYLjey72vQNwQOw@mail.gmail.com> (raw)
In-Reply-To: <87mwbnu6kf.fsf@lifelogs.com>
[-- Attachment #1: Type: text/plain, Size: 5395 bytes --]
> Is there a way to specify it per server?
Agreed. I have redone the patch and added some more features:
1. erc-ssl-servers: Alist of servers (ADDRESS PORT) for which ERC will
always connect to using SSL.
2. erc-use-ssl: If non-nill, all connections will be made using SSL.
3. erc-ssl-blacklist: Alist of server ERC will connect to without SSL.
Only useful when erc-use-ssl is non-nil.
erc-ssl-servers is also used to compute the initial port number
displayed on the minibuffer during user input when ERC is run
interactively.
Here's an example (non-interactive):
(setq erc-ssl-servers '(("irc.freenode.net" 7000)))
(erc :server "irc.freenode.net" :nick "foo") #creates a SSL connection
(setq erc-use-ssl t)
(erc :server "<some server supporting ssl>":port <ssl port>) # will
use a SSL connection
(setq erc-ssl-blacklist '(("irc.example.org"))) #assuming 1234 accepts
SSL connections
(erc :server "irc.example.org" :nick "foo") #connection does not use SSL
I have attached the patch, do tell me something else needs to be added/fixed.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 3bd9ff3..151482c 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -809,6 +809,27 @@ If nil, ERC will call `system-name' to get this
information."
:type '(choice (const :tag "Default system name" nil)
string))
+(defcustom erc-ssl-servers nil
+ "Alist of networks to which ERC will connect to using SSL.
+(ADDRESS PORT) where ADDRESS is the address of the IRC network
+and PORT is the port on which the network accepts SSL connections."
+ :group 'erc
+ :type '(repeat
+ (list :tag "Network"
+ (string :tag "Network address")
+ (integer :tag "SSL Port"))))
+
+(defcustom erc-use-ssl nil
+ "If non-nil, all connections made by ERC will use SSL."
+ :group 'erc
+ :type 'boolean)
+
+(defcustom erc-ssl-blacklist nil
+ "List of server ERC will connect to without SSL.
+Only useful when `erc-use-ssl' is non-nil"
+ :group 'erc
+ :type '(repeat (list string)))
+
(defcustom erc-ignore-list nil
"List of regexps matching user identifiers to ignore.
@@ -2094,18 +2115,23 @@ functions in here get called with the
parameters SERVER and NICK."
;;;###autoload
(defun erc-select-read-args ()
"Prompt the user for values of nick, server, port, and password."
- (let (user-input server port nick passwd)
+ (let (user-input server port nick passwd ssl-port)
(setq user-input (read-from-minibuffer
"IRC server: "
(erc-compute-server) nil nil 'erc-server-history-list))
+ (setq ssl-port (if (not (assoc-string user-input erc-ssl-blacklist t))
+ (nth 1 (assoc-string user-input erc-ssl-servers t))
+ nil))
(if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
(setq port (erc-string-to-port (match-string 2 user-input))
user-input (match-string 1 user-input))
(setq port
(erc-string-to-port (read-from-minibuffer
- "IRC port: " (erc-port-to-string
- (erc-compute-port))))))
+ "IRC port: " (if ssl-port
+ (number-to-string ssl-port)
+ (erc-port-to-string
+ (erc-compute-port)))))))
(if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
(setq nick (match-string 1 user-input)
@@ -2145,7 +2171,7 @@ functions in here get called with the parameters
SERVER and NICK."
;;;###autoload
(cl-defun erc (&key (server (erc-compute-server))
- (port (erc-compute-port))
+ (port nil)
(nick (erc-compute-nick))
password
(full-name (erc-compute-full-name)))
@@ -2156,7 +2182,7 @@ It permits you to select connection parameters,
and then starts ERC.
Non-interactively, it takes the keyword arguments
(server (erc-compute-server))
- (port (erc-compute-port))
+ (port nil)
(nick (erc-compute-nick))
password
(full-name (erc-compute-full-name)))
@@ -2166,10 +2192,23 @@ That is, if called with
(erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
then the server and full-name will be set to those values, whereas
-`erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
-be invoked for the values of the other parameters."
+ `erc-compute-nick' and `erc-compute-full-name' will be invoked
+ for the values of the other parameters. If the server address is found in
+ `erc-ssl-servers', the port corresponding to the server will be used, or
+ `erc-compute-port' will be invoked for its value."
(interactive (erc-select-read-args))
- (erc-open server port nick full-name t password))
+ (let* ((use-ssl (equal nil (assoc-string server erc-ssl-blacklist t)))
+ (erc-server-connect-function
+ (if (or (and erc-use-ssl use-ssl)
+ (assoc-string server erc-ssl-servers t))
+ 'erc-open-tls-stream
+ 'open-network-stream))
+ (ssl-port (nth 1 (assoc-string server erc-ssl-servers t))))
+
+ (if (and (numberp port) (numberp ssl-port) use-ssl)
+ (setq port ssl-port)
+ (setq port (erc-compute-port)))
+ (erc-open server port nick full-name t password)))
;;;###autoload
(defalias 'erc-select 'erc)
--
Vibhav Pant
vibhavp@gmail.com
[-- Attachment #2: erc-ssl-option.patch --]
[-- Type: text/x-patch, Size: 4228 bytes --]
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 3bd9ff3..151482c 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -809,6 +809,27 @@ If nil, ERC will call `system-name' to get this information."
:type '(choice (const :tag "Default system name" nil)
string))
+(defcustom erc-ssl-servers nil
+ "Alist of networks to which ERC will connect to using SSL.
+(ADDRESS PORT) where ADDRESS is the address of the IRC network
+and PORT is the port on which the network accepts SSL connections."
+ :group 'erc
+ :type '(repeat
+ (list :tag "Network"
+ (string :tag "Network address")
+ (integer :tag "SSL Port"))))
+
+(defcustom erc-use-ssl nil
+ "If non-nil, all connections made by ERC will use SSL."
+ :group 'erc
+ :type 'boolean)
+
+(defcustom erc-ssl-blacklist nil
+ "List of server ERC will connect to without SSL.
+Only useful when `erc-use-ssl' is non-nil"
+ :group 'erc
+ :type '(repeat (list string)))
+
(defcustom erc-ignore-list nil
"List of regexps matching user identifiers to ignore.
@@ -2094,18 +2115,23 @@ functions in here get called with the parameters SERVER and NICK."
;;;###autoload
(defun erc-select-read-args ()
"Prompt the user for values of nick, server, port, and password."
- (let (user-input server port nick passwd)
+ (let (user-input server port nick passwd ssl-port)
(setq user-input (read-from-minibuffer
"IRC server: "
(erc-compute-server) nil nil 'erc-server-history-list))
+ (setq ssl-port (if (not (assoc-string user-input erc-ssl-blacklist t))
+ (nth 1 (assoc-string user-input erc-ssl-servers t))
+ nil))
(if (string-match "\\(.*\\):\\(.*\\)\\'" user-input)
(setq port (erc-string-to-port (match-string 2 user-input))
user-input (match-string 1 user-input))
(setq port
(erc-string-to-port (read-from-minibuffer
- "IRC port: " (erc-port-to-string
- (erc-compute-port))))))
+ "IRC port: " (if ssl-port
+ (number-to-string ssl-port)
+ (erc-port-to-string
+ (erc-compute-port)))))))
(if (string-match "\\`\\(.*\\)@\\(.*\\)" user-input)
(setq nick (match-string 1 user-input)
@@ -2145,7 +2171,7 @@ functions in here get called with the parameters SERVER and NICK."
;;;###autoload
(cl-defun erc (&key (server (erc-compute-server))
- (port (erc-compute-port))
+ (port nil)
(nick (erc-compute-nick))
password
(full-name (erc-compute-full-name)))
@@ -2156,7 +2182,7 @@ It permits you to select connection parameters, and then starts ERC.
Non-interactively, it takes the keyword arguments
(server (erc-compute-server))
- (port (erc-compute-port))
+ (port nil)
(nick (erc-compute-nick))
password
(full-name (erc-compute-full-name)))
@@ -2166,10 +2192,23 @@ That is, if called with
(erc :server \"irc.freenode.net\" :full-name \"Harry S Truman\")
then the server and full-name will be set to those values, whereas
-`erc-compute-port', `erc-compute-nick' and `erc-compute-full-name' will
-be invoked for the values of the other parameters."
+ `erc-compute-nick' and `erc-compute-full-name' will be invoked
+ for the values of the other parameters. If the server address is found in
+ `erc-ssl-servers', the port corresponding to the server will be used, or
+ `erc-compute-port' will be invoked for its value."
(interactive (erc-select-read-args))
- (erc-open server port nick full-name t password))
+ (let* ((use-ssl (equal nil (assoc-string server erc-ssl-blacklist t)))
+ (erc-server-connect-function
+ (if (or (and erc-use-ssl use-ssl)
+ (assoc-string server erc-ssl-servers t))
+ 'erc-open-tls-stream
+ 'open-network-stream))
+ (ssl-port (nth 1 (assoc-string server erc-ssl-servers t))))
+
+ (if (and (numberp port) (numberp ssl-port) use-ssl)
+ (setq port ssl-port)
+ (setq port (erc-compute-port)))
+ (erc-open server port nick full-name t password)))
;;;###autoload
(defalias 'erc-select 'erc)
next prev parent reply other threads:[~2014-08-02 17:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-30 9:19 [PATCH] Add option to ERC to make all connections use SSL Vibhav Pant
2014-07-30 20:22 ` Ted Zlatanov
2014-07-31 16:46 ` Vibhav Pant
2014-07-31 20:40 ` Glenn Morris
2014-08-01 16:28 ` Vibhav Pant
2014-08-01 23:35 ` Ted Zlatanov
2014-08-02 17:47 ` Vibhav Pant [this message]
2014-08-02 19:11 ` Josh
2014-08-06 17:12 ` Ted Zlatanov
2014-08-08 2:09 ` Vibhav Pant
2014-08-03 14:39 ` John Zorn
2014-08-06 16:14 ` Josh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+T2Sh0tdaEPZ_REyet435sM+wTDbznoT5qdYLjey72vQNwQOw@mail.gmail.com \
--to=vibhavp@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).