From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marco Pessotto Newsgroups: gmane.emacs.bugs Subject: bug#8772: [PATCH] rcirc: support TLS/SSL and arbitrary connection method Date: Tue, 31 May 2011 10:43:59 +0200 Message-ID: <878vtns1io.fsf@universe.krase.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1306831531 16318 80.91.229.12 (31 May 2011 08:45:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 31 May 2011 08:45:31 +0000 (UTC) To: 8772@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 31 10:45:16 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QRKZa-0002Wv-Qa for geb-bug-gnu-emacs@m.gmane.org; Tue, 31 May 2011 10:45:11 +0200 Original-Received: from localhost ([::1]:55264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKZa-0008GN-EE for geb-bug-gnu-emacs@m.gmane.org; Tue, 31 May 2011 04:45:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:36458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKZU-000841-QU for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:45:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRKZT-0000vB-EY for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:45:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKZT-0000v7-C4 for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:45:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QRKZT-00017f-27; Tue, 31 May 2011 04:45:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marco Pessotto Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 May 2011 08:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8772 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13068314644217 (code B ref -1); Tue, 31 May 2011 08:45:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 May 2011 08:44:24 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QRKYp-00015x-5B for submit@debbugs.gnu.org; Tue, 31 May 2011 04:44:23 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QRKYm-00015b-4F for submit@debbugs.gnu.org; Tue, 31 May 2011 04:44:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRKYf-0000c2-Nv for submit@debbugs.gnu.org; Tue, 31 May 2011 04:44:14 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:56506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKYf-0000by-MM for submit@debbugs.gnu.org; Tue, 31 May 2011 04:44:13 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:42883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKYe-0007EB-8d for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:44:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRKYb-0000bI-Q2 for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:44:12 -0400 Original-Received: from mail-fx0-f41.google.com ([209.85.161.41]:53418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRKYb-0000bE-G5 for bug-gnu-emacs@gnu.org; Tue, 31 May 2011 04:44:09 -0400 Original-Received: by fxm18 with SMTP id 18so3492605fxm.0 for ; Tue, 31 May 2011 01:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=2ExPr9ZevG/nb2JJqoq5I5kd8+hy7OgsNszfe3y9vDg=; b=pWaSftnBOI52UqHNc6Qy29fqhlqJbA2GrCqAMh9HBzzEoCyarXOjdEKw+gZ8pd2pBM IINgt0N4aUL58V0BFiO9lZ+OrWlwt1QWt2BW8GVfwYWK9nbsJhs4yxA4IfdT16u3kRH9 MqouXMfeH+zFgIFrAike55OEZmonr+t8WJ5yc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; b=Zuf2db0WERAdgvIIAN3056qPssmS7cd/Tf6Fbo7rGqe5uC9z6fIU+0MwdiGewE67eq uqE/2nVJE4xlqSg/fa7p4QNZ/JbaasOTH4N5amwRFSlh8+Mz4UAzGdSG1wGNGCUGfzuq Uv9r3xRP1/tEEm/p1JJ0cNimVEyLyxx2KaXUc= Original-Received: by 10.223.98.82 with SMTP id p18mr1877651fan.64.1306831448640; Tue, 31 May 2011 01:44:08 -0700 (PDT) Original-Received: from localhost (93-137-173-231.adsl.net.t-com.hr [93.137.173.231]) by mx.google.com with ESMTPS id q14sm997446faa.27.2011.05.31.01.44.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 May 2011 01:44:07 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 31 May 2011 04:45:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46840 Archived-At: --=-=-= >From emacs-devel: Hello there. I'm writing you to submit a patch for rcirc.el to give it support for SSL connections. For example, the following 2 servers will connect with SSL, one using a custom function (which can be anything, and re-implements this idea https://github.com/nealey/rcirc/wiki ), one simply adding :use-tls t. (setq rcirc-server-alist '(("irc.freenode.net" :nick "nick" :user-name "username" :port 6697 ;; use open-tls-stream as function to connect :custom-connect-function open-tls-stream :channels ("#rcirc" "#emacs")) ("irc.otherserver.org" :nick "nick" :username "username" ;; just say use-tls, more intuitive ;; also prompted when C-u M-x rcirc :use-tls t :port 7000 :channels ("#channel1" "#channel 2")))) The last 2 chunks of the patch are meant to strip the IRC colors. Not really part of the "connection" patch, but IMHO useful. The patch is meant to be applied to the latest revision published on github by rcy: https://github.com/rcy/rcirc In case you're interested, I signed the emacs papers some years ago. Bests Marco --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=ssl-custom-function.patch Content-Description: ssl patch diff --git a/rcirc.el b/rcirc.el index 093892a..a0bcaf1 100644 --- a/rcirc.el +++ b/rcirc.el @@ -46,6 +46,7 @@ (require 'ring) (require 'time-date) (eval-when-compile (require 'cl)) +(require 'tls) (defgroup rcirc nil "Simple IRC client." @@ -76,6 +77,19 @@ for this connection. VALUE must be a number or string. If absent, `rcirc-default-port' is used. +`:use-tls' + +VALUE is a boolean. If true, the connection will be established +using the tls.el library. If absent, `rcirc-default-use-tls' is +used, which in turn default to nil (false). + +`:custom-connect-function' + +VALUE is a custom function to open the connection and must take +the same arguments of `open-network-stream' If you set this, +the :use-tls parameter is ignored (as you are supposed to set the +connection by yourself) + `:user-name' VALUE must be a string. If absent, `rcirc-default-user-name' is @@ -102,6 +116,8 @@ connected to automatically." (:user-name string) (:password string) (:full-name string) + (:use-tls boolean) + (:custom-connect-function function) (:channels (repeat string))))) :group 'rcirc) @@ -110,6 +126,11 @@ connected to automatically." :type 'integer :group 'rcirc) +(defcustom rcirc-default-use-tls nil + "Use SSL/TLS by default?" + :type 'boolean + :group 'rcirc) + (defcustom rcirc-default-nick (user-login-name) "Your nick." :type 'string @@ -409,6 +430,7 @@ If ARG is non-nil, instead prompt for connection parameters." 'rcirc-user-name-history)) (password (read-passwd "IRC Password: " nil (plist-get server-plist :password))) + (use-tls (yes-or-no-p "Use SSL/TLS? ")) (channels (split-string (read-string "IRC Channels: " (mapconcat 'identity @@ -418,7 +440,7 @@ If ARG is non-nil, instead prompt for connection parameters." "[, ]+" t))) (rcirc-connect server port nick user-name rcirc-default-full-name - channels password)) + channels password use-tls)) ;; connect to servers in `rcirc-server-alist' (let (connected-servers) (dolist (c rcirc-server-alist) @@ -430,6 +452,9 @@ If ARG is non-nil, instead prompt for connection parameters." (full-name (or (plist-get (cdr c) :full-name) rcirc-default-full-name)) (channels (plist-get (cdr c) :channels)) + (use-tls (or (plist-get (cdr c) :use-tls) + rcirc-default-use-tls)) + (custom-connect-function (plist-get (cdr c) :custom-connect-function)) (password (plist-get (cdr c) :password))) (when server (let (connected) @@ -439,13 +464,15 @@ If ARG is non-nil, instead prompt for connection parameters." (if (not connected) (condition-case e (rcirc-connect server port nick user-name - full-name channels password) + full-name channels password use-tls + custom-connect-function) (quit (message "Quit connecting to %s" server))) (with-current-buffer (process-buffer connected) + (if (process-contact (get-buffer-process + (current-buffer)) :host) (setq connected-servers - (cons (process-contact (get-buffer-process - (current-buffer)) :host) - connected-servers)))))))) + (cons (process-name connected) + connected-servers))))))))) (when connected-servers (message "Already connected to %s" (if (cdr connected-servers) @@ -471,7 +498,8 @@ If ARG is non-nil, instead prompt for connection parameters." ;;;###autoload (defun rcirc-connect (server &optional port nick user-name - full-name startup-channels password) + full-name startup-channels password use-tls + custom-connect-function) (save-excursion (message "Connecting to %s..." server) (let* ((inhibit-eol-conversion) @@ -484,7 +512,16 @@ If ARG is non-nil, instead prompt for connection parameters." (user-name (or user-name rcirc-default-user-name)) (full-name (or full-name rcirc-default-full-name)) (startup-channels startup-channels) - (process (make-network-process :name server :host server :service port-number))) + (process)) + (if (functionp custom-connect-function) + (setq process (funcall custom-connect-function server nil server port-number)) + (if use-tls + (setq process (open-tls-stream server nil server port-number)) + (setq process (open-network-stream server nil server port-number)))) + (unless process + (error (concat + (format "Couldn't connect to %s on %d " server port-number) + (when use-tls "using TLS/SSL")))) ;; set up process (set-process-coding-system process 'raw-text 'raw-text) (switch-to-buffer (rcirc-generate-new-buffer-name process nil)) @@ -698,7 +735,7 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.") "Send PROCESS a STRING plus a newline." (let ((string (concat (encode-coding-string string rcirc-encode-coding-system) "\n"))) - (unless (eq (process-status process) 'open) + (unless (member (process-status process) '(open run)) (error "Network connection to %s is not open" (process-name process))) (rcirc-debug process string) @@ -1401,7 +1438,8 @@ Returns nil if the information is not recorded." (- rcirc-current-line last-activity-line)))) (defvar rcirc-markup-text-functions - '(rcirc-markup-attributes + '(rcirc-markup-strip-irc-colors + rcirc-markup-attributes rcirc-markup-my-nick rcirc-markup-urls rcirc-markup-keywords @@ -2302,6 +2340,10 @@ keywords when no KEYWORD is given." (insert (rcirc-facify (format-time-string rcirc-time-format) 'rcirc-timestamp))) +(defun rcirc-markup-strip-irc-colors (sender response) + (while (re-search-forward "\C-c\\([0-9][0-9]?\\(,[0-9][0-9]?\\)?\\)?" nil t) + (delete-region (match-beginning 0) (match-end 0)))) + (defun rcirc-markup-attributes (sender response) (while (re-search-forward "\\([\C-b\C-_\C-v]\\).*?\\(\\1\\|\C-o\\)" nil t) (rcirc-add-face (match-beginning 0) (match-end 0) --=-=-= -- Marco --=-=-=--