all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vibhav Pant <vibhavp@gmail.com>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: [PATCH] ERC: support for IRCv3.1 CAP
Date: Tue, 21 Jun 2016 12:56:06 +0530	[thread overview]
Message-ID: <CA+T2Sh3ECsrJ41QFCjZSZMOR3tHfc0nBbv7izu1_ht+70O7ovQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

The IRCv3.1 specification adds the CAP command, allowing
client/servers to enable/disable certain capabilities. The following
patch adds the CAP command, and the response handler for CAP LS, LIST,
REQ, ACK, NAK and error 410 (ERR_INVALIDCAPCMD) messages.

Thanks,
Vibhav
-- 
Vibhav Pant
vibhavp@gmail.com

[-- Attachment #2: cap.diff --]
[-- Type: text/plain, Size: 3977 bytes --]

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index bbb7ccb..3fe252a 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1528,6 +1528,31 @@ erc-handle-unknown-server-response
        parsed 'notice nil
        'WALLOPS ?n nick ?m message))))
 
+(define-erc-response-handler (CAP)
+  "capabilities" nil
+  (let ((subcmd (nth 1 (erc-response.command-args parsed))))
+    (cond
+     ((string-equal subcmd "LS")
+      (erc-display-message
+       parsed 'notice nil
+       'CAPLS ?c (string-join
+                  (cddr (erc-response.command-args parsed)) " ")))
+     ((string-equal subcmd "LIST")
+      (erc-display-message
+       parsed 'notice nil
+       'CAPLIST ?c (string-join
+                    (cddr (erc-response.command-args parsed)) " ")))
+     ((string-equal subcmd "ACK")
+      (erc-display-message
+       parsed 'notice nil
+       'CAPACK ?c (string-join
+                   (cddr (erc-response.command-args parsed)) " ")))
+     ((string-equal subcmd "NAK")
+      (erc-display-message
+       parsed '(notice error) nil
+       'CAPNAK ?c (string-join
+                   (cddr (erc-response.command-args parsed)) " "))))))
+
 (define-erc-response-handler (001)
   "Set `erc-server-current-nick' to reflect server settings and display the welcome message."
   nil
@@ -2012,6 +2037,11 @@ erc-server-322-message
     (erc-display-message parsed 'notice 'active 's671
                          ?n nick ?a securemsg)))
 
+(define-erc-response-handler (410)
+  "Invalid CAP subcommand" nil
+  (erc-display-message parsed '(notice error) nil 's410
+                       ?c (nth 1 (erc-response.command-args parsed))))
+
 (define-erc-response-handler (431 445 446 451 462 463 464 481 483 484 485
                                   491 501 502)
   ;; 431 - No nickname given
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 8501e2c..72b52d0 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -3832,6 +3832,35 @@ erc-cmd-MASSUNBAN
 
 (defalias 'erc-cmd-MUB 'erc-cmd-MASSUNBAN)
 
+(defun erc-cap-command (cmd param)
+  (erc-server-send
+   (format "CAP %s %s" cmd
+           (if (= (length param) 0) (nth 0 param)
+             (concat ":" (string-join param " ")))))
+  (erc-server-send "CAP END"))
+
+(defun erc-cmd-CAP (subcmd &rest params)
+  "IRCv3 Capability negotation.
+
+/cap REQ PARAMS requests a the server to enable capabilities PARAMS.
+Capabilities prefixed with '-' are disabled.
+
+/cap ACK PARAMS acknowledges a change for capabilities PARAMS.  Capabilities
+prefixed with '-' are acknowledged as disabled.
+
+/cap LS lists capabilities supported by the server.
+
+/cap LIST lists capabilities associated with this connection.
+
+/cap END ends capability negotiation."
+  (cond
+   ((string= "REQ" (upcase subcmd))
+    (erc-cap-command "REQ" params))
+   ((string= "ACK" (upcase subcmd))
+    (erc-cap-command "ACK" params))
+   (t (erc-server-send (format "CAP %s %s" (upcase subcmd)
+                               (string-join params " "))))))
+
 ;;;; End of IRC commands
 
 (defun erc-ensure-channel-name (channel)
@@ -6544,6 +6573,10 @@ erc-define-catalog
    (undefined-ctcp . "Undefined CTCP query received. Silently ignored")
    (variable-not-bound . "Variable not bound!")
    (ACTION . "* %n %a")
+   (CAPACK . "Capability change acknowledged: %c")
+   (CAPLS . "Capabilities supported by the server: %c")
+   (CAPLIST . "Capabilities active on this connection: %c")
+   (CAPNAK . "Capability change was rejected for: %c")
    (CTCP-CLIENTINFO . "Client info for %n: %m")
    (CTCP-ECHO . "Echo %n: %m")
    (CTCP-FINGER . "Finger info for %n: %m")
@@ -6609,6 +6642,7 @@ erc-define-catalog
    (s404   . "%c: Cannot send to channel")
    (s405   . "%c: You have joined too many channels")
    (s406   . "%n: There was no such nickname")
+   (s410   . "Invalid CAP subcommand: %c")
    (s412   . "No text to send")
    (s421   . "%c: Unknown command")
    (s431   . "No nickname given")

             reply	other threads:[~2016-06-21  7:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-21  7:26 Vibhav Pant [this message]
2016-06-21 15:22 ` [PATCH] ERC: support for IRCv3.1 CAP Kelvin White
2016-06-25 14:04   ` Vibhav Pant
2016-09-22 16:06     ` Vibhav Pant
2016-09-22 17:35       ` Kelvin White
2016-09-22 17:51       ` John Wiegley
2016-09-22 18:00         ` Vibhav Pant

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+T2Sh3ECsrJ41QFCjZSZMOR3tHfc0nBbv7izu1_ht+70O7ovQ@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.