From bd5ab8cc039e7636f79427051473fee6d0f17d65 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Jul 2020 23:35:36 +0200 Subject: [PATCH] Move IRCv3 separately, shorten one bit of the tokenizer --- include/mappings.h | 41 +++++++++++++++++++++++++---------------- src/uirc.c | 33 +++++++++++++++++---------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/include/mappings.h b/include/mappings.h index e98072e..2282ae3 100644 --- a/include/mappings.h +++ b/include/mappings.h @@ -11,20 +11,13 @@ #define MBMASK_WALLOPS 2 /* 010 */ #define MBMASK_INVIS 4 /* 100 */ +#define UIRC_FCMD ADMIN enum { - ACCOUNT = 10, /* https://ircv3.net/specs/extensions/account-notify-3.1 */ - ACC, /* https://github.com/ircv3/ircv3-specifications/pull/276 */ - ACK, /* https://ircv3.net/specs/extensions/labeled-response */ ADMIN, - AUTHENTICATE, /* https://ircv3.net/specs/extensions/sasl-3.1 */ AWAY, - BATCH, /* https://ircv3.net/specs/extensions/batch-3.2 */ - CAP, /* https://ircv3.net/specs/core/capability-negotiation */ - CHGHOST, /* https://ircv3.net/specs/extensions/chghost-3.2 */ CONNECT, DIE, ERROR, - FAIL, /* https://ircv3.net/specs/extensions/standard-replies */ INFO, INVITE, ISON, @@ -35,11 +28,9 @@ enum { LIST, LUSERS, MODE, - MONITOR, /* https://ircv3.net/specs/core/monitor-3.2 */ MOTD, NAMES, NICK, - NOTE, /* https://ircv3.net/specs/extensions/standard-replies */ NOTICE, OPER, PART, @@ -49,13 +40,10 @@ enum { PRIVMSG, QUIT, REHASH, - RENAME, /* https://github.com/ircv3/ircv3-specifications/pull/420 */ RESTART, - RESUME, /* https://github.com/ircv3/ircv3-specifications/pull/306 */ SERVER, SERVICE, SERVLIST, - SETNAME, /* https://ircv3.net/specs/extensions/setname */ SQUERY, SQUIT, STATS, @@ -68,11 +56,28 @@ enum { USERS, VERSION, WALLOPS, - WARN, /* https://ircv3.net/specs/extensions/standard-replies */ - WEBIRC, /* https://ircv3.net/specs/extensions/webirc */ WHO, WHOIS, - WHOWAS + WHOWAS, +#define UIRC_LCMD WHOWAS +#ifdef UIRC_IRCV3 + ACC, /* https://github.com/ircv3/ircv3-specifications/pull/276 */ + ACCOUNT, /* https://ircv3.net/specs/extensions/account-notify-3.1 */ + ACK, /* https://ircv3.net/specs/extensions/labeled-response */ + AUTHENTICATE, /* https://ircv3.net/specs/extensions/sasl-3.1 */ + BATCH, /* https://ircv3.net/specs/extensions/batch-3.2 */ + CAP, /* https://ircv3.net/specs/core/capability-negotiation */ + CHGHOST, /* https://ircv3.net/specs/extensions/chghost-3.2 */ + FAIL, /* https://ircv3.net/specs/extensions/standard-replies */ + MONITOR, /* https://ircv3.net/specs/core/monitor-3.2 */ + NOTE, /* https://ircv3.net/specs/extensions/standard-replies */ + RENAME, /* https://github.com/ircv3/ircv3-specifications/pull/420 */ + RESUME, /* https://github.com/ircv3/ircv3-specifications/pull/306 */ + SETNAME, /* https://ircv3.net/specs/extensions/setname */ + WARN, /* https://ircv3.net/specs/extensions/standard-replies */ + WEBIRC, /* https://ircv3.net/specs/extensions/webirc */ +#define UIRC_LCMD WEBIRC +#endif }; enum { RPL_WELCOME = 1, @@ -81,6 +86,7 @@ enum { RPL_MYINFO = 4, RPL_BOUNCE = 5, +#ifdef UIRC_IRCV3 /* TO IRCv3 WG: * please, stop complicating implementations * get people in the WG that actually care about the protocol and understand why and how standards are written @@ -89,6 +95,7 @@ enum { * Read the above and go speak with them, or just don't use IRCv3 :) */ RPL_ISUPPORT = 5, +#endif RPL_TRACELINK = 200, RPL_TRACECONNECTING = 201, @@ -209,6 +216,7 @@ enum { ERR_UMODEUNKNOWNFLAG = 501, ERR_USERSDONTMATCH = 502, +#ifdef UIRC_IRCV3 /* https://ircv3.net/registry */ RPL_STARTTLS = 670, ERR_STARTTLS = 691, @@ -228,5 +236,6 @@ enum { ERR_SASLABORTED = 906, ERR_SASLALREADY = 907, ERR_SASLMECHS = 908 +#endif }; #endif diff --git a/src/uirc.c b/src/uirc.c index 0d1f0b4..fa54311 100644 --- a/src/uirc.c +++ b/src/uirc.c @@ -18,15 +18,8 @@ #include "uirc.h" const char* const uirc_ircmd[] = { - [ACCOUNT] = "ACCOUNT", - [ACC] = "ACC", - [ACK] = "ACK", [ADMIN] = "ADMIN", - [AUTHENTICATE] = "AUTHENTICATE", [AWAY] = "AWAY", - [BATCH] = "BATCH", - [CAP] = "CAP", - [CHGHOST] = "CHGHOST", [CONNECT] = "CONNECT", [DIE] = "DIE", [ERROR] = "ERROR", @@ -52,9 +45,7 @@ const char* const uirc_ircmd[] = { [PRIVMSG] = "PRIVMSG", [QUIT] = "QUIT", [REHASH] = "REHASH", - [RENAME] = "RENAME", [RESTART] = "RESTART", - [RESUME] = "RESUME", [SERVER] = "SERVER", [SERVICE] = "SERVICE", [SERVLIST] = "SERVLIST", @@ -70,10 +61,22 @@ const char* const uirc_ircmd[] = { [USER] = "USER", [VERSION] = "VERSION", [WALLOPS] = "WALLOPS", - [WEBIRC] = "WEBIRC", [WHOIS] = "WHOIS", [WHOWAS] = "WHOWAS", - [WHO] = "WHO"}; + [WHO] = "WHO", +#ifdef UIRC_IRCV3 + [ACCOUNT] = "ACCOUNT", + [ACC] = "ACC", + [ACK] = "ACK", + [AUTHENTICATE] = "AUTHENTICATE", + [BATCH] = "BATCH", + [CAP] = "CAP", + [CHGHOST] = "CHGHOST", + [RENAME] = "RENAME", + [RESUME] = "RESUME", + [WEBIRC] = "WEBIRC" +#endif +}; struct tagmapping { const char* name; @@ -83,8 +86,8 @@ signed int Ircmd_stoi(char* str) { if (str == NULL) return ERR_UIRC_NULL_ARGS; - for (unsigned short i = ACCOUNT; i <= WHO; i++) { - if ((uirc_ircmd[i] != NULL) && (strcmp(uirc_ircmd[i], str) == 0)) + for (unsigned short i = UIRC_FCMD; i <= UIRC_LCMD; i++) { + if (uirc_ircmd[i] != NULL && strcmp(uirc_ircmd[i], str) == 0) return i; } return ERR_UIRC_UNKNOWN_TOKEN; @@ -125,10 +128,8 @@ signed int Tok_mesg(char* str, IRC_Message* out) return ERR_UIRC_INVALID_FORMAT; } out->args[i] = NULL; - if (*progr == ':') - ++progr; if (*progr != '\0') - out->trailing = progr; + out->trailing = (*progr == ':') ? progr + 1 : progr; return 1; } signed int Assm_mesg(char* buf, IRC_Message* in)