all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] ERC: support for IRCv3.1 CAP
@ 2016-06-21  7:26 Vibhav Pant
  2016-06-21 15:22 ` Kelvin White
  0 siblings, 1 reply; 7+ messages in thread
From: Vibhav Pant @ 2016-06-21  7:26 UTC (permalink / raw)
  To: emacs-devel@gnu.org

[-- 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")

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-22 18:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-21  7:26 [PATCH] ERC: support for IRCv3.1 CAP Vibhav Pant
2016-06-21 15:22 ` 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

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.