[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add option to ERC to make all connections use SSL.

From: Vibhav Pant
Subject: Re: [PATCH] Add option to ERC to make all connections use SSL.
Date: Sat, 2 Aug 2014 23:17:13 +0530

> 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

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
   :type '(choice (const :tag "Default system name" nil)

+(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."
 (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

 (cl-defun erc (&key (server (erc-compute-server))
-                    (port   (erc-compute-port))
+                    (port    nil)
                     (nick   (erc-compute-nick))
                     (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))
    (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)))

 (defalias 'erc-select 'erc)

Vibhav Pant

Attachment: erc-ssl-option.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]