+/* Global functions */
+
+/**
+ * Handler for the IRCv3 command "CAP".
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
+ */
+GLOBAL bool
+IRC_CAP(CLIENT *Client, REQUEST *Req)
+{
+ assert(Client != NULL);
+ assert(Req != NULL);
+
+ _IRC_ARGC_BETWEEN_OR_RETURN_(Client, Req, 1, 2)
+
+ LogDebug("Got \"%s %s\" command from \"%s\" ...",
+ Req->command, Req->argv[0], Client_ID(Client));
+
+ if (Req->argc == 1) {
+ if (strcasecmp(Req->argv[0], "CLEAR") == 0)
+ return Handle_CAP_CLEAR(Client);
+ if (strcasecmp(Req->argv[0], "END") == 0)
+ return Handle_CAP_END(Client);
+ }
+ if (Req->argc >= 1 && Req->argc <= 2) {
+ if (strcasecmp(Req->argv[0], "LS") == 0)
+ return Handle_CAP_LS(Client, Req->argv[1]);
+ if (strcasecmp(Req->argv[0], "LIST") == 0)
+ return Handle_CAP_LIST(Client, Req->argv[1]);
+ }
+ if (Req->argc == 2) {
+ if (strcasecmp(Req->argv[0], "REQ") == 0)
+ return Handle_CAP_REQ(Client, Req->argv[1]);
+ if (strcasecmp(Req->argv[0], "ACK") == 0)
+ return Handle_CAP_ACK(Client, Req->argv[1]);
+ }
+
+ return IRC_WriteErrClient(Client, ERR_INVALIDCAP_MSG,
+ Client_ID(Client), Req->argv[0]);
+}
+