+/**
+ * Parse capability string and return numeric flag value.
+ *
+ * @param Args The string containing space-separated capability names.
+ * @return Changed capability flags or 0 on error.
+ */
+int
+Parse_CAP(int Capabilities, char *Args)
+{
+ static char tmp[COMMAND_LEN];
+ char *ptr;
+
+ assert(Args != NULL);
+
+ strlcpy(tmp, Args, sizeof(tmp));
+
+ ptr = strtok(tmp, " ");
+ while (ptr) {
+ if (*ptr == '-') {
+ /* drop capabilities */
+ ptr++;
+ if (strcmp(ptr, "multi-prefix") == 0)
+ Capabilities &= ~CLIENT_CAP_MULTI_PREFIX;
+ else
+ return -1;
+ } else {
+ /* request capabilities */
+ if (strcmp(ptr, "multi-prefix") == 0)
+ Capabilities |= CLIENT_CAP_MULTI_PREFIX;
+ else
+ return -1;
+ }
+ ptr = strtok(NULL, " ");
+ }
+
+ return Capabilities;
+}
+
+/**
+ * Return textual representation of capability flags.
+ *
+ * Please note: this function returns a pointer to a global buffer and
+ * therefore isn't thread safe!
+ *
+ * @param Capabilities Capability flags (bitmask).
+ * @return Pointer to textual representation.
+ */
+char *
+Get_CAP_String(int Capabilities)
+{
+ static char txt[COMMAND_LEN];
+
+ txt[0] = '\0';
+
+ if (Capabilities & CLIENT_CAP_MULTI_PREFIX)
+ strlcat(txt, "multi-prefix ", sizeof(txt));
+
+ return txt;
+}
+