From d55cc68e375cd284de2b457c0e9eb5ecd201ce6a Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Wed, 7 Apr 2021 21:45:44 +0000 Subject: [PATCH] Lookup tables and organizing - Add predefined strings by IRCv3 standards, RFC2812 and CTCP - Rename most things to singular version - Add lookup functions and converters - Remove assert for non-pointer value - Fix two tests on standard build - Update clang tidy checks --- .clang-tidy | 2 +- CMakeLists.txt | 61 ++-- include/{assemblers.h => assembler.h} | 2 +- include/command.h | 229 +++++++++++++++ include/commands.h | 72 ----- include/ctcp.h | 146 ++-------- include/{errors.h => error.h} | 0 include/memory.h | 3 +- include/{modes.h => mode.h} | 20 +- include/replies.h | 186 ------------ include/tag.h | 39 +++ include/{tokenizers.h => tokenizer.h} | 2 +- include/{types.h => type.h} | 2 +- include/uirc.h | 24 +- include/{validators.h => validator.h} | 2 +- src/{assemblers => assembler}/message.c | 6 +- src/{assemblers => assembler}/tag.c | 6 +- src/{assemblers => assembler}/user.c | 6 +- src/command/command.c | 40 +++ src/command/reply.c | 197 +++++++++++++ src/ctcp/ctcp.c | 270 ++++++++++++++++++ src/error/error.c | 2 +- src/memory/list.c | 1 - src/memory/struct.c | 6 +- src/{modes/modes.c => mode/mode.c} | 18 +- src/tag/tag.c | 32 +++ src/{tests => test}/CMakeLists.txt | 0 src/{tests => test}/allocs.c | 0 src/{tests => test}/common.c | 0 src/{tests => test}/common.h | 0 src/{tests => test}/earlytrail.c | 0 src/{tests => test}/errno.c | 0 src/{tests => test}/fullloop.c | 5 +- src/{tests => test}/manassm.c | 4 +- src/{tests => test}/modes.c | 14 +- src/{tests => test}/optcrlf.c | 0 src/{tokenizers => tokenizer}/message.c | 29 +- src/{tokenizers => tokenizer}/tag.c | 8 +- src/{tokenizers => tokenizer}/user.c | 8 +- .../validators.c => validator/validator.c} | 2 +- 40 files changed, 963 insertions(+), 481 deletions(-) rename include/{assemblers.h => assembler.h} (97%) create mode 100644 include/command.h delete mode 100644 include/commands.h rename include/{errors.h => error.h} (100%) rename include/{modes.h => mode.h} (84%) delete mode 100644 include/replies.h create mode 100644 include/tag.h rename include/{tokenizers.h => tokenizer.h} (98%) rename include/{types.h => type.h} (99%) rename include/{validators.h => validator.h} (96%) rename src/{assemblers => assembler}/message.c (95%) rename src/{assemblers => assembler}/tag.c (94%) rename src/{assemblers => assembler}/user.c (93%) create mode 100644 src/command/command.c create mode 100644 src/command/reply.c create mode 100644 src/ctcp/ctcp.c rename src/{modes/modes.c => mode/mode.c} (85%) create mode 100644 src/tag/tag.c rename src/{tests => test}/CMakeLists.txt (100%) rename src/{tests => test}/allocs.c (100%) rename src/{tests => test}/common.c (100%) rename src/{tests => test}/common.h (100%) rename src/{tests => test}/earlytrail.c (100%) rename src/{tests => test}/errno.c (100%) rename src/{tests => test}/fullloop.c (93%) rename src/{tests => test}/manassm.c (92%) rename src/{tests => test}/modes.c (76%) rename src/{tests => test}/optcrlf.c (100%) rename src/{tokenizers => tokenizer}/message.c (87%) rename src/{tokenizers => tokenizer}/tag.c (94%) rename src/{tokenizers => tokenizer}/user.c (92%) rename src/{validators/validators.c => validator/validator.c} (98%) diff --git a/.clang-tidy b/.clang-tidy index c0cc988..3d1436d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'bugprone-*,performance-*,portability-*,readability-*,-readability-braces-around-statements,-readability-isolate-declaration,-readability-else-after-return,-readability-braces-around-statements,misc-*,modernize-*,clang-analyzer-core.*,clang-analyzer-security.*,clang-analyzer-unix.*,clang-analyzer-optin.portability.UnixAPI,clang-analyzer-optin.performance.Padding' +Checks: 'performance-*,portability-*,readability-*,bugprone-*,concurrency-*,llvm-*,clang-analyzer-core.*,clang-analyzer-nullability.*,clang-analyzer-optin.portability.UnixAPI,clang-analyzer-security.*,clang-analyzer-unix.*,clang-analyzer-valist.*,clang-analyzer-apiModeling.*,cert-*-c,-readability-isolate-declaration,-readability-braces-around-statements,-readability-magic-numbers' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false diff --git a/CMakeLists.txt b/CMakeLists.txt index c2bd6cd..4dd5231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,29 +19,31 @@ OPTION(CODE_ANALYZER "Analyze the code statically" OFF) OPTION(CODE_COVERAGE "Build with coverage tools" OFF) set(UIRC_SOURCE - src/assemblers/message.c - src/assemblers/user.c + src/assembler/message.c + src/assembler/user.c + src/command/command.c + src/command/reply.c src/error/error.c - src/modes/modes.c src/memory/list.c src/memory/struct.c - src/tokenizers/message.c - src/tokenizers/user.c + src/mode/mode.c + src/tokenizer/message.c + src/tokenizer/user.c ) set(UIRC_HEADERS - include/assemblers.h - include/commands.h + include/assembler.h + include/command.h include/ctcp.h - include/errors.h + include/error.h include/memory.h include/misc.h - include/modes.h - include/replies.h - include/tokenizers.h - include/types.h + include/mode.h + include/tag.h + include/tokenizer.h + include/type.h include/uirc.h - include/validators.h + include/validator.h ) # Libraries used @@ -57,8 +59,9 @@ if (BUILD_IRCV3) add_compile_definitions(UIRC_FEATURE_IRCV3) set(UIRC_SOURCE ${UIRC_SOURCE} - src/assemblers/tag.c - src/tokenizers/tag.c + src/assembler/tag.c + src/tokenizer/tag.c + src/tag/tag.c ) endif() if (BUILD_VALIDATORS) @@ -66,11 +69,15 @@ if (BUILD_VALIDATORS) add_compile_definitions(UIRC_FEATURE_VALIDATORS) set(UIRC_SOURCE ${UIRC_SOURCE} - src/validators/validators.c + src/validator/validator.c ) - set(UIRC_HEADERS - ${UIRC_HEADERS} - src/validators/validators.h +endif() +if (BUILD_CTCP) + message(STATUS "CTCP support will be built") + add_compile_definitions(UIRC_FEATURE_CTCP) + set(UIRC_SOURCE + ${UIRC_SOURCE} + src/ctcp/ctcp.c ) endif() if(BUILD_DOCS) @@ -93,15 +100,15 @@ if(BUILD_DOCS) endif() if (BUILD_TESTS) message(STATUS "Tests are going to be built.") - add_subdirectory(src/tests) + add_subdirectory(src/test) enable_testing() - add_test(NAME "FullLoop" COMMAND "fullloop") - add_test(NAME "EarlyTrail" COMMAND "earlytrail") - add_test(NAME "OptCRLF" COMMAND "optcrlf") - add_test(NAME "Allocators" COMMAND "allocs") - add_test(NAME "ManualAssemblers" COMMAND "manassm") - add_test(NAME "ErrorNumbers" COMMAND "errno") - add_test(NAME "ModeBitmasks" COMMAND "modes") + add_test(NAME "FullLoop" COMMAND "fullloop" ) + add_test(NAME "EarlyTrail" COMMAND "earlytrail") + add_test(NAME "OptCRLF" COMMAND "optcrlf" ) + add_test(NAME "Allocators" COMMAND "allocs" ) + add_test(NAME "ManualAssemblers" COMMAND "manassm" ) + add_test(NAME "ErrorNumbers" COMMAND "errno" ) + add_test(NAME "Modes" COMMAND "modes" ) endif() add_library(uirc ${UIRC_SOURCE}) diff --git a/include/assemblers.h b/include/assembler.h similarity index 97% rename from include/assemblers.h rename to include/assembler.h index 30b0d9c..a3de97f 100644 --- a/include/assemblers.h +++ b/include/assembler.h @@ -18,7 +18,7 @@ /*! \file */ -#include "types.h" // IRC_User IRC_Message +#include "type.h" // IRC_User IRC_Message #include // llist_t #include // ssize_t ssize_t diff --git a/include/command.h b/include/command.h new file mode 100644 index 0000000..8f5f091 --- /dev/null +++ b/include/command.h @@ -0,0 +1,229 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +/*! \file */ + +#include // uint_least16_t + +#ifndef UIRC_GUARD_PUBLIC_COMMANDS +#define UIRC_GUARD_PUBLIC_COMMANDS + +enum uirc_table_command { + IRC_CMD_PASS, + IRC_CMD_NICK, + IRC_CMD_USER, + IRC_CMD_OPER, + IRC_CMD_MODE, + IRC_CMD_SERVICE, + IRC_CMD_QUIT, + IRC_CMD_SQUIT, + IRC_CMD_JOIN, + IRC_CMD_PART, + IRC_CMD_TOPIC, + IRC_CMD_NAMES, + IRC_CMD_LIST, + IRC_CMD_INVITE, + IRC_CMD_KICK, + IRC_CMD_PRIVMSG, + IRC_CMD_NOTICE, + IRC_CMD_MOTD, + IRC_CMD_LUSERS, + IRC_CMD_VERSION, + IRC_CMD_STATS, + IRC_CMD_LINKS, + IRC_CMD_TIME, + IRC_CMD_CONNECT, + IRC_CMD_TRACE, + IRC_CMD_ADMIN, + IRC_CMD_INFO, + IRC_CMD_SERVLIST, + IRC_CMD_SQUERY, + IRC_CMD_WHO, + IRC_CMD_WHOIS, + IRC_CMD_WHOWAS, + IRC_CMD_KILL, + IRC_CMD_PING, + IRC_CMD_PONG, + IRC_CMD_ERROR, + IRC_CMD_AWAY, + IRC_CMD_REHASH, + IRC_CMD_DIE, + IRC_CMD_RESTART, + IRC_CMD_SUMMON, + IRC_CMD_USERS, + IRC_CMD_WALLOPS, + IRC_CMD_USERHOST, + IRC_CMD_ISON, +}; +const char* IRC_CMD(enum uirc_table_command cmd); + +enum uirc_table_replies { + IRC_RPL_WELCOME, + IRC_RPL_YOURHOST, + IRC_RPL_CREATED, + IRC_RPL_MYINFO, + IRC_RPL_BOUNCE, + +#ifdef UIRC_FEATURE_IRCV3 + IRC_RPL_ISUPPORT, +#endif /* UIRC_FEATURE_IRCV3 */ + + IRC_RPL_TRACELINK, + IRC_RPL_TRACECONNECTING, + IRC_RPL_TRACEHANDSHAKE, + IRC_RPL_TRACEUNKNOWN, + IRC_RPL_TRACEOPERATOR, + IRC_RPL_TRACEUSER, + IRC_RPL_TRACESERVER, + IRC_RPL_TRACENEWTYPE, + IRC_RPL_STATSLINKINFO, + IRC_RPL_STATSCOMMANDS, + IRC_RPL_STATSCLINE, + IRC_RPL_STATSNLINE, + IRC_RPL_STATSILINE, + IRC_RPL_STATSKLINE, + IRC_RPL_STATSYLINE, + IRC_RPL_ENDOFSTATS, + IRC_RPL_UMODEIS, + IRC_RPL_STATSLLINE, + IRC_RPL_STATSUPTIME, + IRC_RPL_STATSOLINE, + IRC_RPL_STATSHLINE, + IRC_RPL_LUSERCLIENT, + IRC_RPL_LUSEROP, + IRC_RPL_LUSERUNKNOWN, + IRC_RPL_LUSERCHANNELS, + IRC_RPL_LUSERME, + IRC_RPL_ADMINME, + IRC_RPL_ADMINLOC1, + IRC_RPL_ADMINLOC2, + IRC_RPL_ADMINEMAIL, + IRC_RPL_TRACELOG, + IRC_RPL_NONE, + IRC_RPL_AWAY, + IRC_RPL_USERHOST, + IRC_RPL_ISON, + IRC_RPL_UNAWAY, + IRC_RPL_NOWAWAY, + IRC_RPL_WHOISUSER, + IRC_RPL_WHOISSERVER, + IRC_RPL_WHOISOPERATOR, + IRC_RPL_WHOWASUSER, + IRC_RPL_ENDOFWHO, + IRC_RPL_WHOISIDLE, + IRC_RPL_ENDOFWHOIS, + IRC_RPL_WHOISCHANNELS, + IRC_RPL_LISTSTART, + IRC_RPL_LIST, + IRC_RPL_LISTEND, + IRC_RPL_CHANNELMODEIS, + IRC_RPL_NOTOPIC, + IRC_RPL_TOPIC, + IRC_RPL_INVITING, + IRC_RPL_SUMMONING, + IRC_RPL_VERSION, + IRC_RPL_WHOREPLY, + IRC_RPL_NAMREPLY, + IRC_RPL_LINKS, + IRC_RPL_ENDOFLINKS, + IRC_RPL_ENDOFNAMES, + IRC_RPL_BANLIST, + IRC_RPL_ENDOFBANLIST, + IRC_RPL_ENDOFWHOWAS, + IRC_RPL_INFO, + IRC_RPL_MOTD, + IRC_RPL_ENDOFINFO, + IRC_RPL_MOTDSTART, + IRC_RPL_ENDOFMOTD, + IRC_RPL_YOUREOPER, + IRC_RPL_REHASHING, + IRC_RPL_TIME, + IRC_RPL_USERSSTART, + IRC_RPL_USERS, + IRC_RPL_ENDOFUSERS, + IRC_RPL_NOUSERS, + + IRC_ERR_NOSUCHNICK, + IRC_ERR_NOSUCHSERVER, + IRC_ERR_NOSUCHCHANNEL, + IRC_ERR_CANNOTSENDTOCHAN, + IRC_ERR_TOOMANYCHANNELS, + IRC_ERR_WASNOSUCHNICK, + IRC_ERR_TOOMANYTARGETS, + IRC_ERR_NOORIGIN, + IRC_ERR_NORECIPIENT, + IRC_ERR_NOTEXTTOSEND, + IRC_ERR_NOTOPLEVEL, + IRC_ERR_WILDTOPLEVEL, + IRC_ERR_UNKNOWNCOMMAND, + IRC_ERR_NOMOTD, + IRC_ERR_NOADMININFO, + IRC_ERR_FILEIRC_ERROR, + IRC_ERR_NONICKNAMEGIVEN, + IRC_ERR_IRC_ERRONEUSNICKNAME, + IRC_ERR_NICKNAMEINUSE, + IRC_ERR_NICKCOLLISION, + IRC_ERR_USERNOTINCHANNEL, + IRC_ERR_NOTONCHANNEL, + IRC_ERR_USERONCHANNEL, + IRC_ERR_NOLOGIN, + IRC_ERR_SUMMONDISABLED, + IRC_ERR_USERSDISABLED, + IRC_ERR_NOTREGISTERED, + IRC_ERR_NEEDMOREPARAMS, + IRC_ERR_ALREADYREGISTRED, + IRC_ERR_NOPERMFORHOST, + IRC_ERR_PASSWDMISMATCH, + IRC_ERR_YOUREBANNEDCREEP, + IRC_ERR_KEYSET, + IRC_ERR_CHANNELISFULL, + IRC_ERR_UNKNOWNMODE, + IRC_ERR_INVITEONLYCHAN, + IRC_ERR_BANNEDFROMCHAN, + IRC_ERR_BADCHANNELKEY, + IRC_ERR_NOPRIVILEGES, + IRC_ERR_CHANOPRIVSNEEDED, + IRC_ERR_CANTKILLSERVER, + IRC_ERR_NOOPERHOST, + IRC_ERR_UMODEUNKNOWNFLAG, + IRC_ERR_USERSDONTMATCH, + +#ifdef UIRC_FEATURE_IRCV3 + IRC_RPL_STARTTLS, + IRC_ERR_STARTTLS, + IRC_RPL_MONONLINE, + IRC_RPL_MONOFFLINE, + IRC_RPL_MONLIST, + IRC_RPL_ENDOFMONLIST, + IRC_ERR_MOLISTFULL, + IRC_RPL_LOGGEDIN, + IRC_RPL_LOGGEDOUT, + IRC_ERR_NICKLOCKED, + IRC_RPL_SASLSUCCESS, + IRC_ERR_SASLFAIL, + IRC_ERR_SASLTOOLONG, + IRC_ERR_SASLABORTED, + IRC_ERR_SASLALREADY, + IRC_ERR_SASLMECHS, +#endif /* UIRC_FEATURE_IRCV3 */ +}; +uint_least16_t IRC_RPL(enum uirc_table_replies rpl); +const char* IRC_RPL_STR(enum uirc_table_replies rpl); + +#endif /* UIRC_GUARD_PUBLIC_COMMANDS */ + diff --git a/include/commands.h b/include/commands.h deleted file mode 100644 index 37ecea7..0000000 --- a/include/commands.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) - * Copyright (c) 2019-2021 Alex-David Denes - * - * uIRC is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * uIRC is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with uIRC. If not, see . - */ - -/*! \file */ - -#ifndef UIRC_GUARD_PUBLIC_COMMANDS -#define UIRC_GUARD_PUBLIC_COMMANDS - -#define IRC_CMD_PASS "PASS" -#define IRC_CMD_NICK "NICK" -#define IRC_CMD_USER "USER" -#define IRC_CMD_OPER "OPER" -#define IRC_CMD_MODE "MODE" -#define IRC_CMD_SERVICE "SERVICE" -#define IRC_CMD_QUIT "QUIT" -#define IRC_CMD_SQUIT "SQUIT" -#define IRC_CMD_JOIN "JOIN" -#define IRC_CMD_PART "PART" -#define IRC_CMD_MODE "MODE" -#define IRC_CMD_TOPIC "TOPIC" -#define IRC_CMD_NAMES "NAMES" -#define IRC_CMD_LIST "LIST" -#define IRC_CMD_INVITE "INVITE" -#define IRC_CMD_KICK "KICK" -#define IRC_CMD_PRIVMSG "PRIVMSG" -#define IRC_CMD_NOTICE "NOTICE" -#define IRC_CMD_MOTD "MOTD" -#define IRC_CMD_LUSERS "LUSERS" -#define IRC_CMD_VERSION "VERSION" -#define IRC_CMD_STATS "STATS" -#define IRC_CMD_LINKS "LINKS" -#define IRC_CMD_TIME "TIME" -#define IRC_CMD_CONNECT "CONNECT" -#define IRC_CMD_TRACE "TRACE" -#define IRC_CMD_ADMIN "ADMIN" -#define IRC_CMD_INFO "INFO" -#define IRC_CMD_SERVLIST "SERVLIST" -#define IRC_CMD_SQUERY "SQUERY" -#define IRC_CMD_WHO "WHO" -#define IRC_CMD_WHOIS "WHOIS" -#define IRC_CMD_WHOWAS "WHOWAS" -#define IRC_CMD_KILL "KILL" -#define IRC_CMD_PING "PING" -#define IRC_CMD_PONG "PONG" -#define IRC_CMD_ERROR "ERROR" -#define IRC_CMD_AWAY "AWAY" -#define IRC_CMD_REHASH "REHASH" -#define IRC_CMD_DIE "DIE" -#define IRC_CMD_RESTART "RESTART" -#define IRC_CMD_SUMMON "SUMMON" -#define IRC_CMD_USERS "USERS" -#define IRC_CMD_WALLOPS "WALLOPS" -#define IRC_CMD_USERHOST "USERHOST" -#define IRC_CMD_ISON "ISON" - -#endif /* UIRC_GUARD_PUBLIC_COMMANDS */ - diff --git a/include/ctcp.h b/include/ctcp.h index 0c6a51e..a699253 100644 --- a/include/ctcp.h +++ b/include/ctcp.h @@ -18,24 +18,27 @@ /*! \file */ +#include // uint_least8_t + #ifndef UIRC_GUARD_PUBLIC_CTCP #define UIRC_GUARD_PUBLIC_CTCP -#ifdef UIRC_FEATURE_CTCP -enum formatting { - IRC_CTCP_BOLD = 0x02, - IRC_CTCP_COLOR = 0x03, - IRC_CTCP_COLOR_HEX = 0x04, - IRC_CTCP_RESET = 0x0F, - IRC_CTCP_MONOSPACE = 0x11, - IRC_CTCP_REVERSE = 0x16, - IRC_CTCP_ITALICS = 0x1D, - IRC_CTCP_STRIKETHROUGH = 0x1E, - IRC_CTCP_UNDERLINE = 0x1F, +enum uirc_table_ctcp_formats { + IRC_CTCP_BOLD, + IRC_CTCP_COLOR, + IRC_CTCP_COLOR_HEX, + IRC_CTCP_RESET, + IRC_CTCP_MONOSPACE, + IRC_CTCP_REVERSE, + IRC_CTCP_ITALICS, + IRC_CTCP_STRIKETHROUGH, + IRC_CTCP_UNDERLINE, }; -enum colors { - IRC_CTCP_COLORS_WHITE = 0, - IRC_CTCP_COLORS_BLACK = 1, +int_least8_t IRC_CTCP_FORMAT(enum uirc_table_ctcp_formats fmt); + +enum uirc_table_ctcp_named_colors { + IRC_CTCP_COLORS_WHITE, + IRC_CTCP_COLORS_BLACK, IRC_CTCP_COLORS_BLUE, IRC_CTCP_COLORS_GREEN, IRC_CTCP_COLORS_RED, @@ -50,117 +53,12 @@ enum colors { IRC_CTCP_COLORS_PINK, IRC_CTCP_COLORS_GREY, IRC_CTCP_COLORS_LIGHT_GREY, - IRC_CTCP_COLORS_DEFAULT = 99, + IRC_CTCP_COLORS_DEFAULT, }; -short UIRC_FORMAT_ANSI[] = { - [IRC_CTCP_COLORS_WHITE] = 97, - [IRC_CTCP_COLORS_BLACK] = 30, - [IRC_CTCP_COLORS_BLUE] = 34, - [IRC_CTCP_COLORS_GREEN] = 32, - [IRC_CTCP_COLORS_RED] = 31, - [IRC_CTCP_COLORS_BROWN] = 94, - [IRC_CTCP_COLORS_MAGENTA] = 35, - [IRC_CTCP_COLORS_ORANGE] = 166, - [IRC_CTCP_COLORS_YELLOW] = 33, - [IRC_CTCP_COLORS_LIGHT_GREEN] = 92, - [IRC_CTCP_COLORS_CYAN] = 36, - [IRC_CTCP_COLORS_LIGHT_CYAN] = 96, - [IRC_CTCP_COLORS_LIGHT_BLUE] = 94, - [IRC_CTCP_COLORS_PINK] = 127, - [IRC_CTCP_COLORS_GREY] = 90, - [IRC_CTCP_COLORS_LIGHT_GREY] = 37, - [IRC_CTCP_COLORS_DEFAULT] = 39, - [IRC_CTCP_BOLD] = 1, - [IRC_CTCP_RESET] = 0, - [IRC_CTCP_REVERSE] = 7, - [IRC_CTCP_ITALICS] = 3, - [IRC_CTCP_STRIKETHROUGH] = 9, - [IRC_CTCP_UNDERLINE] = 4, - [16] = 52, /* See https://modern.ircdocs.horse/formatting.html */ - [17] = 94, - [18] = 100, - [19] = 58, - [20] = 22, - [21] = 29, - [22] = 23, - [23] = 24, - [24] = 17, - [25] = 54, - [26] = 53, - [27] = 89, - [28] = 88, - [29] = 130, - [30] = 142, - [31] = 64, - [32] = 28, - [33] = 35, - [34] = 30, - [35] = 25, - [36] = 18, - [37] = 91, - [38] = 90, - [39] = 125, - [40] = 124, - [41] = 166, - [42] = 184, - [43] = 106, - [44] = 34, - [45] = 49, - [46] = 37, - [47] = 33, - [48] = 19, - [49] = 129, - [50] = 127, - [51] = 161, - [52] = 196, - [53] = 208, - [54] = 226, - [55] = 154, - [56] = 46, - [57] = 86, - [58] = 51, - [59] = 75, - [60] = 21, - [61] = 171, - [62] = 201, - [63] = 198, - [64] = 203, - [65] = 215, - [66] = 227, - [67] = 191, - [68] = 83, - [69] = 122, - [70] = 87, - [71] = 111, - [72] = 63, - [73] = 177, - [74] = 207, - [75] = 205, - [76] = 217, - [77] = 223, - [78] = 229, - [79] = 193, - [80] = 157, - [81] = 158, - [82] = 159, - [83] = 153, - [84] = 147, - [85] = 183, - [86] = 219, - [87] = 212, - [88] = 16, - [89] = 233, - [90] = 235, - [91] = 237, - [92] = 239, - [93] = 241, - [94] = 244, - [95] = 247, - [96] = 250, - [97] = 254, - [98] = 231, -}; -#endif /* UIRC_FEATURE_CTCP */ +int_least8_t IRC_CTCP_COLORS(enum uirc_table_ctcp_named_colors col); + +typedef uint_least8_t rgbcolor[3]; +rgbcolor* uirc_ctcp_to_rgb(uint_least8_t color); #endif /* UIRC_GUARD_PUBLIC_CTCP */ diff --git a/include/errors.h b/include/error.h similarity index 100% rename from include/errors.h rename to include/error.h diff --git a/include/memory.h b/include/memory.h index 52bccb8..b73674a 100644 --- a/include/memory.h +++ b/include/memory.h @@ -18,7 +18,8 @@ /*! \file */ -#include "types.h" // IRC_* +#include "mode.h" // IRC_Modes +#include "type.h" // IRC_* #include // ptrdiff_t diff --git a/include/modes.h b/include/mode.h similarity index 84% rename from include/modes.h rename to include/mode.h index 51ee75f..e402683 100644 --- a/include/modes.h +++ b/include/mode.h @@ -25,15 +25,17 @@ #define UIRC_GUARD_PUBLIC_MODES typedef bool IRC_Modes[(('z' - 'a')) * 2]; -typedef enum { - IRC_MODE_WALLOPS = 'w', - IRC_MODE_INVISIBLE = 'i', - IRC_MODE_AWAY = 'a', - IRC_MODE_RESTRICTED = 'r', - IRC_MODE_OPERATOR = 'o', - IRC_MODE_LOCALOPERATOR = 'O', - IRC_MODE_SERVERNOTICES = 's', -} IRC_Mode; + +enum uirc_table_mode { + IRC_MODE_WALLOPS, + IRC_MODE_INVISIBLE, + IRC_MODE_AWAY, + IRC_MODE_RESTRICTED, + IRC_MODE_OPERATOR, + IRC_MODE_LOCALOPERATOR, + IRC_MODE_SERVERNOTICES, +}; +char IRC_MODE(enum uirc_table_mode mode); bool uirc_mode_toggle(char m, IRC_Modes ms); bool uirc_mode_enable(char m, IRC_Modes ms); diff --git a/include/replies.h b/include/replies.h deleted file mode 100644 index 146ddd1..0000000 --- a/include/replies.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) - * Copyright (c) 2019-2021 Alex-David Denes - * - * uIRC is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * uIRC is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with uIRC. If not, see . - */ - -/*! \file */ - -#ifndef UIRC_GUARD_PUBLIC_REPLIES -#define UIRC_GUARD_PUBLIC_REPLIES - -enum replies { - IRC_RPL_WELCOME = 1, - IRC_RPL_YOURHOST = 2, - IRC_RPL_CREATED = 3, - IRC_RPL_MYINFO = 4, - IRC_RPL_BOUNCE = 5, - -#ifdef UIRC_FEATURE_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 - * - * TO LIBRARY USERS: - * Read the above and go speak with them, or just don't use IRCv3 :) - */ - IRC_RPL_ISUPPORT = 5, -#endif /* UIRC_FEATURE_IRCV3 */ - - IRC_RPL_TRACELINK = 200, - IRC_RPL_TRACECONNECTING = 201, - IRC_RPL_TRACEHANDSHAKE = 202, - IRC_RPL_TRACEUNKNOWN = 203, - IRC_RPL_TRACEOPERATOR = 204, - IRC_RPL_TRACEUSER = 205, - IRC_RPL_TRACESERVER = 206, - IRC_RPL_TRACENEWTYPE = 208, - IRC_RPL_STATSLINKINFO = 211, - IRC_RPL_STATSCOMMANDS = 212, - IRC_RPL_STATSCLINE = 213, - IRC_RPL_STATSNLINE = 214, - IRC_RPL_STATSILINE = 215, - IRC_RPL_STATSKLINE = 216, - IRC_RPL_STATSYLINE = 218, - IRC_RPL_ENDOFSTATS = 219, - IRC_RPL_UMODEIS = 221, - IRC_RPL_STATSLLINE = 241, - IRC_RPL_STATSUPTIME = 242, - IRC_RPL_STATSOLINE = 243, - IRC_RPL_STATSHLINE = 244, - IRC_RPL_LUSERCLIENT = 251, - IRC_RPL_LUSEROP = 252, - IRC_RPL_LUSERUNKNOWN = 253, - IRC_RPL_LUSERCHANNELS = 254, - IRC_RPL_LUSERME = 255, - IRC_RPL_ADMINME = 256, - IRC_RPL_ADMINLOC1 = 257, - IRC_RPL_ADMINLOC2 = 258, - IRC_RPL_ADMINEMAIL = 259, - IRC_RPL_TRACELOG = 261, - IRC_RPL_NONE = 300, - IRC_RPL_AWAY = 301, - IRC_RPL_USERHOST = 302, - IRC_RPL_ISON = 303, - IRC_RPL_UNAWAY = 305, - IRC_RPL_NOWAWAY = 306, - IRC_RPL_WHOISUSER = 311, - IRC_RPL_WHOISSERVER = 312, - IRC_RPL_WHOISOPERATOR = 313, - IRC_RPL_WHOWASUSER = 314, - IRC_RPL_ENDOFWHO = 315, - IRC_RPL_WHOISIDLE = 317, - IRC_RPL_ENDOFWHOIS = 318, - IRC_RPL_WHOISCHANNELS = 319, - IRC_RPL_LISTSTART = 321, - IRC_RPL_LIST = 322, - IRC_RPL_LISTEND = 323, - IRC_RPL_CHANNELMODEIS = 324, - IRC_RPL_NOTOPIC = 331, - IRC_RPL_TOPIC = 332, - IRC_RPL_INVITING = 341, - IRC_RPL_SUMMONING = 342, - IRC_RPL_VERSION = 351, - IRC_RPL_WHOREPLY = 352, - IRC_RPL_NAMREPLY = 353, - IRC_RPL_LINKS = 364, - IRC_RPL_ENDOFLINKS = 365, - IRC_RPL_ENDOFNAMES = 366, - IRC_RPL_BANLIST = 367, - IRC_RPL_ENDOFBANLIST = 368, - IRC_RPL_ENDOFWHOWAS = 369, - IRC_RPL_INFO = 371, - IRC_RPL_MOTD = 372, - IRC_RPL_ENDOFINFO = 374, - IRC_RPL_MOTDSTART = 375, - IRC_RPL_ENDOFMOTD = 376, - IRC_RPL_YOUREOPER = 381, - IRC_RPL_REHASHING = 382, - IRC_RPL_TIME = 391, - IRC_RPL_USERSSTART = 392, - IRC_RPL_USERS = 393, - IRC_RPL_ENDOFUSERS = 394, - IRC_RPL_NOUSERS = 395, - - IRC_ERR_NOSUCHNICK = 401, - IRC_ERR_NOSUCHSERVER = 402, - IRC_ERR_NOSUCHCHANNEL = 403, - IRC_ERR_CANNOTSENDTOCHAN = 404, - IRC_ERR_TOOMANYCHANNELS = 405, - IRC_ERR_WASNOSUCHNICK = 406, - IRC_ERR_TOOMANYTARGETS = 407, - IRC_ERR_NOORIGIN = 409, - IRC_ERR_NORECIPIENT = 411, - IRC_ERR_NOTEXTTOSEND = 412, - IRC_ERR_NOTOPLEVEL = 413, - IRC_ERR_WILDTOPLEVEL = 414, - IRC_ERR_UNKNOWNCOMMAND = 421, - IRC_ERR_NOMOTD = 422, - IRC_ERR_NOADMININFO = 423, - IRC_ERR_FILEIRC_ERROR = 424, - IRC_ERR_NONICKNAMEGIVEN = 431, - IRC_ERR_IRC_ERRONEUSNICKNAME = 432, - IRC_ERR_NICKNAMEINUSE = 433, - IRC_ERR_NICKCOLLISION = 436, - IRC_ERR_USERNOTINCHANNEL = 441, - IRC_ERR_NOTONCHANNEL = 442, - IRC_ERR_USERONCHANNEL = 443, - IRC_ERR_NOLOGIN = 444, - IRC_ERR_SUMMONDISABLED = 445, - IRC_ERR_USERSDISABLED = 446, - IRC_ERR_NOTREGISTERED = 451, - IRC_ERR_NEEDMOREPARAMS = 461, - IRC_ERR_ALREADYREGISTRED = 462, - IRC_ERR_NOPERMFORHOST = 463, - IRC_ERR_PASSWDMISMATCH = 464, - IRC_ERR_YOUREBANNEDCREEP = 465, - IRC_ERR_KEYSET = 467, - IRC_ERR_CHANNELISFULL = 471, - IRC_ERR_UNKNOWNMODE = 472, - IRC_ERR_INVITEONLYCHAN = 473, - IRC_ERR_BANNEDFROMCHAN = 474, - IRC_ERR_BADCHANNELKEY = 475, - IRC_ERR_NOPRIVILEGES = 481, - IRC_ERR_CHANOPRIVSNEEDED = 482, - IRC_ERR_CANTKILLSERVER = 483, - IRC_ERR_NOOPERHOST = 491, - IRC_ERR_UMODEUNKNOWNFLAG = 501, - IRC_ERR_USERSDONTMATCH = 502, - -#ifdef UIRC_FEATURE_IRCV3 - /* https://ircv3.net/registry */ - IRC_RPL_STARTTLS = 670, - IRC_ERR_STARTTLS = 691, - - IRC_RPL_MONONLINE = 730, - IRC_RPL_MONOFFLINE = 731, - IRC_RPL_MONLIST = 732, - IRC_RPL_ENDOFMONLIST = 733, - IRC_ERR_MOLISTFULL = 734, - - IRC_RPL_LOGGEDIN = 900, - IRC_RPL_LOGGEDOUT = 901, - IRC_ERR_NICKLOCKED = 902, - IRC_RPL_SASLSUCCESS = 903, - IRC_ERR_SASLFAIL = 904, - IRC_ERR_SASLTOOLONG = 905, - IRC_ERR_SASLABORTED = 906, - IRC_ERR_SASLALREADY = 907, - IRC_ERR_SASLMECHS = 908, -#endif /* UIRC_FEATURE_IRCV3 */ -}; - -#endif /* UIRC_GUARD_PUBLIC_REPLIES */ - diff --git a/include/tag.h b/include/tag.h new file mode 100644 index 0000000..0f6b5f1 --- /dev/null +++ b/include/tag.h @@ -0,0 +1,39 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +/*! \file */ + +#ifndef UIRC_GUARD_PUBLIC_TAGS +#define UIRC_GUARD_PUBLIC_TAGS + +enum uirc_table_tag { + IRC_TAG_ACCOUNT, + IRC_TAG_BATCH, + IRC_TAG_BOT, + IRC_TAG_LABEL, + IRC_TAG_MSGID, + IRC_TAG_MULTILINE, + IRC_TAG_TIME, + IRC_TAG_REACT, + IRC_TAG_REPLY, + IRC_TAG_TYPING, +}; +const char* IRC_TAG(enum uirc_table_tag tag); + +#endif /* UIRC_GUARD_PUBLIC_TAGS */ + diff --git a/include/tokenizers.h b/include/tokenizer.h similarity index 98% rename from include/tokenizers.h rename to include/tokenizer.h index af27230..2727bbe 100644 --- a/include/tokenizers.h +++ b/include/tokenizer.h @@ -18,7 +18,7 @@ /*! \file */ -#include "types.h" // IRC_User +#include "type.h" // IRC_User #include // llist_t #include // bool diff --git a/include/types.h b/include/type.h similarity index 99% rename from include/types.h rename to include/type.h index 6732699..aa40cd8 100644 --- a/include/types.h +++ b/include/type.h @@ -18,7 +18,7 @@ /*! \file */ -#include "modes.h" +#include "mode.h" #include // llist_t #include // uintmax_t diff --git a/include/uirc.h b/include/uirc.h index 683d57e..6ee0a60 100644 --- a/include/uirc.h +++ b/include/uirc.h @@ -16,14 +16,20 @@ * along with uIRC. If not, see . */ -#include "assemblers.h" -#include "commands.h" -#include "ctcp.h" -#include "errors.h" +#include "assembler.h" +#include "command.h" +#include "error.h" #include "memory.h" #include "misc.h" -#include "modes.h" -#include "replies.h" -#include "tokenizers.h" -#include "types.h" -#include "validators.h" +#include "mode.h" +#include "tokenizer.h" +#include "type.h" +#include "validator.h" + +#ifdef UIRC_FEATURE_IRCV3 +#include "tag.h" +#endif /* UIRC_FEATURE_IRCV3 */ + +#ifdef UIRC_FEATURE_CTCP +#include "ctcp.h" +#endif /* UIRC_FEATURE_CTCP */ diff --git a/include/validators.h b/include/validator.h similarity index 96% rename from include/validators.h rename to include/validator.h index d32109d..41dd479 100644 --- a/include/validators.h +++ b/include/validator.h @@ -18,7 +18,7 @@ /*! \file */ -#include "types.h" // IRC_Message +#include "type.h" // IRC_Message #include diff --git a/src/assemblers/message.c b/src/assembler/message.c similarity index 95% rename from src/assemblers/message.c rename to src/assembler/message.c index 9def288..255049f 100644 --- a/src/assemblers/message.c +++ b/src/assembler/message.c @@ -16,9 +16,9 @@ * along with uIRC. If not, see . */ -#include "assemblers.h" // uirc_assembler_* -#include "errors.h" // uirc_errno -#include "types.h" // IRC_Message IRC_Tag IRC_User +#include "assembler.h" // uirc_assembler_* +#include "error.h" // uirc_errno +#include "type.h" // IRC_Message IRC_Tag IRC_User #include // assert() #include // NULL, snprintf() diff --git a/src/assemblers/tag.c b/src/assembler/tag.c similarity index 94% rename from src/assemblers/tag.c rename to src/assembler/tag.c index a8c523e..c50d9e1 100644 --- a/src/assemblers/tag.c +++ b/src/assembler/tag.c @@ -16,9 +16,9 @@ * along with uIRC. If not, see . */ -#include "assemblers.h" // uirc_assembler_tag_* -#include "errors.h" // uirc_errno -#include "types.h" // IRC_Tag +#include "assembler.h" // uirc_assembler_tag_* +#include "error.h" // uirc_errno +#include "type.h" // IRC_Tag #include // assert() #include // llist_t diff --git a/src/assemblers/user.c b/src/assembler/user.c similarity index 93% rename from src/assemblers/user.c rename to src/assembler/user.c index b24de6c..43c0243 100644 --- a/src/assemblers/user.c +++ b/src/assembler/user.c @@ -16,9 +16,9 @@ * along with uIRC. If not, see . */ -#include "assemblers.h" // Assm_user() -#include "errors.h" // uirc_errno -#include "types.h" // IRC_User +#include "assembler.h" // Assm_user() +#include "error.h" // uirc_errno +#include "type.h" // IRC_User #include // assert() #include // bool diff --git a/src/command/command.c b/src/command/command.c new file mode 100644 index 0000000..16cc77c --- /dev/null +++ b/src/command/command.c @@ -0,0 +1,40 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +#include "command.h" + +static const char* const cmd_table[] = { + [IRC_CMD_PASS] = "PASS", [IRC_CMD_NICK] = "NICK", [IRC_CMD_USER] = "USER", [IRC_CMD_OPER] = "OPER", + [IRC_CMD_MODE] = "MODE", [IRC_CMD_SERVICE] = "SERVICE", [IRC_CMD_QUIT] = "QUIT", [IRC_CMD_SQUIT] = "SQUIT", + [IRC_CMD_JOIN] = "JOIN", [IRC_CMD_PART] = "PART", [IRC_CMD_TOPIC] = "TOPIC", [IRC_CMD_NAMES] = "NAMES", + [IRC_CMD_LIST] = "LIST", [IRC_CMD_INVITE] = "INVITE", [IRC_CMD_KICK] = "KICK", [IRC_CMD_PRIVMSG] = "PRIVMSG", + [IRC_CMD_NOTICE] = "NOTICE", [IRC_CMD_MOTD] = "MOTD", [IRC_CMD_LUSERS] = "LUSERS", [IRC_CMD_VERSION] = "VERSION", + [IRC_CMD_STATS] = "STATS", [IRC_CMD_LINKS] = "LINKS", [IRC_CMD_TIME] = "TIME", [IRC_CMD_CONNECT] = "CONNECT", + [IRC_CMD_TRACE] = "TRACE", [IRC_CMD_ADMIN] = "ADMIN", [IRC_CMD_INFO] = "INFO", [IRC_CMD_SERVLIST] = "SERVLIST", + [IRC_CMD_SQUERY] = "SQUERY", [IRC_CMD_WHO] = "WHO", [IRC_CMD_WHOIS] = "WHOIS", [IRC_CMD_WHOWAS] = "WHOWAS", + [IRC_CMD_KILL] = "KILL", [IRC_CMD_PING] = "PING", [IRC_CMD_PONG] = "PONG", [IRC_CMD_ERROR] = "ERROR", + [IRC_CMD_AWAY] = "AWAY", [IRC_CMD_REHASH] = "REHASH", [IRC_CMD_DIE] = "DIE", [IRC_CMD_RESTART] = "RESTART", + [IRC_CMD_SUMMON] = "SUMMON", [IRC_CMD_USERS] = "USERS", [IRC_CMD_WALLOPS] = "WALLOPS", [IRC_CMD_USERHOST] = "USERHOST", + [IRC_CMD_ISON] = "ISON", +}; + +const char* +IRC_CMD(enum uirc_table_command cmd) +{ + return cmd_table[cmd]; +} diff --git a/src/command/reply.c b/src/command/reply.c new file mode 100644 index 0000000..9dfb76a --- /dev/null +++ b/src/command/reply.c @@ -0,0 +1,197 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +#include "command.h" + +#include // uint_least16_t +#include // snprintf() + +static const uint_least16_t reply_table[] = { + [IRC_RPL_WELCOME] = 1, + [IRC_RPL_YOURHOST] = 2, + [IRC_RPL_CREATED] = 3, + [IRC_RPL_MYINFO] = 4, + [IRC_RPL_BOUNCE] = 5, + +#ifdef UIRC_FEATURE_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 + * + * TO LIBRARY USERS: + * Read the above and go speak with them, or just don't use IRCv3 :) + */ + [IRC_RPL_ISUPPORT] = 5, +#endif /* UIRC_FEATURE_IRCV3 */ + + [IRC_RPL_TRACELINK] = 200, + [IRC_RPL_TRACECONNECTING] = 201, + [IRC_RPL_TRACEHANDSHAKE] = 202, + [IRC_RPL_TRACEUNKNOWN] = 203, + [IRC_RPL_TRACEOPERATOR] = 204, + [IRC_RPL_TRACEUSER] = 205, + [IRC_RPL_TRACESERVER] = 206, + [IRC_RPL_TRACENEWTYPE] = 208, + [IRC_RPL_STATSLINKINFO] = 211, + [IRC_RPL_STATSCOMMANDS] = 212, + [IRC_RPL_STATSCLINE] = 213, + [IRC_RPL_STATSNLINE] = 214, + [IRC_RPL_STATSILINE] = 215, + [IRC_RPL_STATSKLINE] = 216, + [IRC_RPL_STATSYLINE] = 218, + [IRC_RPL_ENDOFSTATS] = 219, + [IRC_RPL_UMODEIS] = 221, + [IRC_RPL_STATSLLINE] = 241, + [IRC_RPL_STATSUPTIME] = 242, + [IRC_RPL_STATSOLINE] = 243, + [IRC_RPL_STATSHLINE] = 244, + [IRC_RPL_LUSERCLIENT] = 251, + [IRC_RPL_LUSEROP] = 252, + [IRC_RPL_LUSERUNKNOWN] = 253, + [IRC_RPL_LUSERCHANNELS] = 254, + [IRC_RPL_LUSERME] = 255, + [IRC_RPL_ADMINME] = 256, + [IRC_RPL_ADMINLOC1] = 257, + [IRC_RPL_ADMINLOC2] = 258, + [IRC_RPL_ADMINEMAIL] = 259, + [IRC_RPL_TRACELOG] = 261, + [IRC_RPL_NONE] = 300, + [IRC_RPL_AWAY] = 301, + [IRC_RPL_USERHOST] = 302, + [IRC_RPL_ISON] = 303, + [IRC_RPL_UNAWAY] = 305, + [IRC_RPL_NOWAWAY] = 306, + [IRC_RPL_WHOISUSER] = 311, + [IRC_RPL_WHOISSERVER] = 312, + [IRC_RPL_WHOISOPERATOR] = 313, + [IRC_RPL_WHOWASUSER] = 314, + [IRC_RPL_ENDOFWHO] = 315, + [IRC_RPL_WHOISIDLE] = 317, + [IRC_RPL_ENDOFWHOIS] = 318, + [IRC_RPL_WHOISCHANNELS] = 319, + [IRC_RPL_LISTSTART] = 321, + [IRC_RPL_LIST] = 322, + [IRC_RPL_LISTEND] = 323, + [IRC_RPL_CHANNELMODEIS] = 324, + [IRC_RPL_NOTOPIC] = 331, + [IRC_RPL_TOPIC] = 332, + [IRC_RPL_INVITING] = 341, + [IRC_RPL_SUMMONING] = 342, + [IRC_RPL_VERSION] = 351, + [IRC_RPL_WHOREPLY] = 352, + [IRC_RPL_NAMREPLY] = 353, + [IRC_RPL_LINKS] = 364, + [IRC_RPL_ENDOFLINKS] = 365, + [IRC_RPL_ENDOFNAMES] = 366, + [IRC_RPL_BANLIST] = 367, + [IRC_RPL_ENDOFBANLIST] = 368, + [IRC_RPL_ENDOFWHOWAS] = 369, + [IRC_RPL_INFO] = 371, + [IRC_RPL_MOTD] = 372, + [IRC_RPL_ENDOFINFO] = 374, + [IRC_RPL_MOTDSTART] = 375, + [IRC_RPL_ENDOFMOTD] = 376, + [IRC_RPL_YOUREOPER] = 381, + [IRC_RPL_REHASHING] = 382, + [IRC_RPL_TIME] = 391, + [IRC_RPL_USERSSTART] = 392, + [IRC_RPL_USERS] = 393, + [IRC_RPL_ENDOFUSERS] = 394, + [IRC_RPL_NOUSERS] = 395, + + [IRC_ERR_NOSUCHNICK] = 401, + [IRC_ERR_NOSUCHSERVER] = 402, + [IRC_ERR_NOSUCHCHANNEL] = 403, + [IRC_ERR_CANNOTSENDTOCHAN] = 404, + [IRC_ERR_TOOMANYCHANNELS] = 405, + [IRC_ERR_WASNOSUCHNICK] = 406, + [IRC_ERR_TOOMANYTARGETS] = 407, + [IRC_ERR_NOORIGIN] = 409, + [IRC_ERR_NORECIPIENT] = 411, + [IRC_ERR_NOTEXTTOSEND] = 412, + [IRC_ERR_NOTOPLEVEL] = 413, + [IRC_ERR_WILDTOPLEVEL] = 414, + [IRC_ERR_UNKNOWNCOMMAND] = 421, + [IRC_ERR_NOMOTD] = 422, + [IRC_ERR_NOADMININFO] = 423, + [IRC_ERR_FILEIRC_ERROR] = 424, + [IRC_ERR_NONICKNAMEGIVEN] = 431, + [IRC_ERR_IRC_ERRONEUSNICKNAME] = 432, + [IRC_ERR_NICKNAMEINUSE] = 433, + [IRC_ERR_NICKCOLLISION] = 436, + [IRC_ERR_USERNOTINCHANNEL] = 441, + [IRC_ERR_NOTONCHANNEL] = 442, + [IRC_ERR_USERONCHANNEL] = 443, + [IRC_ERR_NOLOGIN] = 444, + [IRC_ERR_SUMMONDISABLED] = 445, + [IRC_ERR_USERSDISABLED] = 446, + [IRC_ERR_NOTREGISTERED] = 451, + [IRC_ERR_NEEDMOREPARAMS] = 461, + [IRC_ERR_ALREADYREGISTRED] = 462, + [IRC_ERR_NOPERMFORHOST] = 463, + [IRC_ERR_PASSWDMISMATCH] = 464, + [IRC_ERR_YOUREBANNEDCREEP] = 465, + [IRC_ERR_KEYSET] = 467, + [IRC_ERR_CHANNELISFULL] = 471, + [IRC_ERR_UNKNOWNMODE] = 472, + [IRC_ERR_INVITEONLYCHAN] = 473, + [IRC_ERR_BANNEDFROMCHAN] = 474, + [IRC_ERR_BADCHANNELKEY] = 475, + [IRC_ERR_NOPRIVILEGES] = 481, + [IRC_ERR_CHANOPRIVSNEEDED] = 482, + [IRC_ERR_CANTKILLSERVER] = 483, + [IRC_ERR_NOOPERHOST] = 491, + [IRC_ERR_UMODEUNKNOWNFLAG] = 501, + [IRC_ERR_USERSDONTMATCH] = 502, + +#ifdef UIRC_FEATURE_IRCV3 + /* https://ircv3.net/registry */ + [IRC_RPL_STARTTLS] = 670, + [IRC_ERR_STARTTLS] = 691, + + [IRC_RPL_MONONLINE] = 730, + [IRC_RPL_MONOFFLINE] = 731, + [IRC_RPL_MONLIST] = 732, + [IRC_RPL_ENDOFMONLIST] = 733, + [IRC_ERR_MOLISTFULL] = 734, + + [IRC_RPL_LOGGEDIN] = 900, + [IRC_RPL_LOGGEDOUT] = 901, + [IRC_ERR_NICKLOCKED] = 902, + [IRC_RPL_SASLSUCCESS] = 903, + [IRC_ERR_SASLFAIL] = 904, + [IRC_ERR_SASLTOOLONG] = 905, + [IRC_ERR_SASLABORTED] = 906, + [IRC_ERR_SASLALREADY] = 907, + [IRC_ERR_SASLMECHS] = 908, +#endif /* UIRC_FEATURE_IRCV3 */ +}; + +uint_least16_t +IRC_RPL(enum uirc_table_replies rpl) +{ + return reply_table[rpl]; +} + +const char* +IRC_RPL_STR(enum uirc_table_replies rpl) +{ + static char cmd[4]; + snprintf(cmd, 3, "%i", reply_table[rpl]); + return cmd; +} diff --git a/src/ctcp/ctcp.c b/src/ctcp/ctcp.c new file mode 100644 index 0000000..33f81d7 --- /dev/null +++ b/src/ctcp/ctcp.c @@ -0,0 +1,270 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +#include "ctcp.h" + +#include + +// Tables +static int_least8_t ctcp_formats[] = { + [IRC_CTCP_BOLD] = 0x02, [IRC_CTCP_COLOR] = 0x03, [IRC_CTCP_COLOR_HEX] = 0x04, + [IRC_CTCP_RESET] = 0x0F, [IRC_CTCP_MONOSPACE] = 0x11, [IRC_CTCP_REVERSE] = 0x16, + [IRC_CTCP_ITALICS] = 0x1D, [IRC_CTCP_STRIKETHROUGH] = 0x1E, [IRC_CTCP_UNDERLINE] = 0x1F, +}; +static int_least8_t ctcp_named_colors[] = { + [IRC_CTCP_COLORS_WHITE] = 0, [IRC_CTCP_COLORS_BLACK] = 1, [IRC_CTCP_COLORS_BLUE] = 2, [IRC_CTCP_COLORS_GREEN] = 3, + [IRC_CTCP_COLORS_RED] = 4, [IRC_CTCP_COLORS_BROWN] = 5, [IRC_CTCP_COLORS_MAGENTA] = 6, [IRC_CTCP_COLORS_ORANGE] = 7, + [IRC_CTCP_COLORS_YELLOW] = 8, [IRC_CTCP_COLORS_LIGHT_GREEN] = 9, [IRC_CTCP_COLORS_CYAN] = 10, [IRC_CTCP_COLORS_LIGHT_CYAN] = 11, + [IRC_CTCP_COLORS_LIGHT_BLUE] = 12, [IRC_CTCP_COLORS_PINK] = 13, [IRC_CTCP_COLORS_GREY] = 14, [IRC_CTCP_COLORS_LIGHT_GREY] = 15, + [IRC_CTCP_COLORS_DEFAULT] = 99, +}; + +// CTCP to ANSI format mappings +static short ansi_formats[] = { + [IRC_CTCP_BOLD] = 1, [IRC_CTCP_RESET] = 0, [IRC_CTCP_REVERSE] = 7, + [IRC_CTCP_ITALICS] = 3, [IRC_CTCP_STRIKETHROUGH] = 9, [IRC_CTCP_UNDERLINE] = 4, +}; + +// CTCP to ANSI color mappings +static short ansi_colors[] = { + [IRC_CTCP_COLORS_WHITE] = 97, + [IRC_CTCP_COLORS_BLACK] = 30, + [IRC_CTCP_COLORS_BLUE] = 34, + [IRC_CTCP_COLORS_GREEN] = 32, + [IRC_CTCP_COLORS_RED] = 31, + [IRC_CTCP_COLORS_BROWN] = 94, + [IRC_CTCP_COLORS_MAGENTA] = 35, + [IRC_CTCP_COLORS_ORANGE] = 166, + [IRC_CTCP_COLORS_YELLOW] = 33, + [IRC_CTCP_COLORS_LIGHT_GREEN] = 92, + [IRC_CTCP_COLORS_CYAN] = 36, + [IRC_CTCP_COLORS_LIGHT_CYAN] = 96, + [IRC_CTCP_COLORS_LIGHT_BLUE] = 94, + [IRC_CTCP_COLORS_PINK] = 127, + [IRC_CTCP_COLORS_GREY] = 90, + [IRC_CTCP_COLORS_LIGHT_GREY] = 37, + [IRC_CTCP_COLORS_DEFAULT] = 39, + [16] = 52, /* See https://modern.ircdocs.horse/formatting.html */ + [17] = 94, + [18] = 100, + [19] = 58, + [20] = 22, + [21] = 29, + [22] = 23, + [23] = 24, + [24] = 17, + [25] = 54, + [26] = 53, + [27] = 89, + [28] = 88, + [29] = 130, + [30] = 142, + [31] = 64, + [32] = 28, + [33] = 35, + [34] = 30, + [35] = 25, + [36] = 18, + [37] = 91, + [38] = 90, + [39] = 125, + [40] = 124, + [41] = 166, + [42] = 184, + [43] = 106, + [44] = 34, + [45] = 49, + [46] = 37, + [47] = 33, + [48] = 19, + [49] = 129, + [50] = 127, + [51] = 161, + [52] = 196, + [53] = 208, + [54] = 226, + [55] = 154, + [56] = 46, + [57] = 86, + [58] = 51, + [59] = 75, + [60] = 21, + [61] = 171, + [62] = 201, + [63] = 198, + [64] = 203, + [65] = 215, + [66] = 227, + [67] = 191, + [68] = 83, + [69] = 122, + [70] = 87, + [71] = 111, + [72] = 63, + [73] = 177, + [74] = 207, + [75] = 205, + [76] = 217, + [77] = 223, + [78] = 229, + [79] = 193, + [80] = 157, + [81] = 158, + [82] = 159, + [83] = 153, + [84] = 147, + [85] = 183, + [86] = 219, + [87] = 212, + [88] = 16, + [89] = 233, + [90] = 235, + [91] = 237, + [92] = 239, + [93] = 241, + [94] = 244, + [95] = 247, + [96] = 250, + [97] = 254, + [98] = 231, +}; + +// CTCP to RGB color mappings +static rgbcolor rgb_maps[] = { + [IRC_CTCP_COLORS_WHITE] = { 0xFF, 0xFF, 0xFF }, + [IRC_CTCP_COLORS_BLACK] = { 0x00, 0x00, 0x00 }, + [IRC_CTCP_COLORS_BLUE] = { 0x00, 0x00, 0x7F }, + [IRC_CTCP_COLORS_GREEN] = { 0x00, 0x93, 0x00 }, + [IRC_CTCP_COLORS_RED] = { 0xFF, 0x00, 0x00 }, + [IRC_CTCP_COLORS_BROWN] = { 0x7F, 0x00, 0x00 }, + [IRC_CTCP_COLORS_MAGENTA] = { 0x9C, 0x00, 0x9C }, + [IRC_CTCP_COLORS_ORANGE] = { 0xFC, 0x7F, 0x00 }, + [IRC_CTCP_COLORS_YELLOW] = { 0xFF, 0xFF, 0x00 }, + [IRC_CTCP_COLORS_LIGHT_GREEN] = { 0x00, 0xFC, 0x00 }, + [IRC_CTCP_COLORS_CYAN] = { 0x00, 0x93, 0x93 }, + [IRC_CTCP_COLORS_LIGHT_CYAN] = { 0x00, 0xFF, 0xFF }, + [IRC_CTCP_COLORS_LIGHT_BLUE] = { 0x00, 0x00, 0xFC }, + [IRC_CTCP_COLORS_PINK] = { 0xFF, 0x00, 0xFF }, + [IRC_CTCP_COLORS_GREY] = { 0x7F, 0x7F, 0x7F }, + [IRC_CTCP_COLORS_LIGHT_GREY] = { 0xD2, 0xD2, 0xD2 }, + [IRC_CTCP_COLORS_DEFAULT] = { 0xFF, 0xFF, 0xFF }, + [16] = { 0x47, 0x00, 0x00 }, /* See https://modern.ircdocs.horse/formatting.html */ + [17] = { 0x47, 0x21, 0x00 }, + [18] = { 0x47, 0x47, 0x00 }, + [19] = { 0x32, 0x47, 0x00 }, + [20] = { 0x00, 0x47, 0x00 }, + [21] = { 0x00, 0x47, 0x2c }, + [22] = { 0x00, 0x47, 0x47 }, + [23] = { 0x00, 0x27, 0x47 }, + [24] = { 0x00, 0x00, 0x47 }, + [25] = { 0x2e, 0x00, 0x47 }, + [26] = { 0x47, 0x00, 0x47 }, + [27] = { 0x47, 0x00, 0x2a }, + [28] = { 0x74, 0x00, 0x00 }, + [29] = { 0x74, 0x3a, 0x00 }, + [30] = { 0x74, 0x74, 0x00 }, + [31] = { 0x51, 0x74, 0x00 }, + [32] = { 0x00, 0x74, 0x00 }, + [33] = { 0x00, 0x74, 0x49 }, + [34] = { 0x00, 0x74, 0x74 }, + [35] = { 0x00, 0x40, 0x74 }, + [36] = { 0x00, 0x00, 0x74 }, + [37] = { 0x4b, 0x00, 0x74 }, + [38] = { 0x74, 0x00, 0x74 }, + [39] = { 0x74, 0x00, 0x45 }, + [40] = { 0xb5, 0x00, 0x00 }, + [41] = { 0xb5, 0x63, 0x00 }, + [42] = { 0xb5, 0xb5, 0x00 }, + [43] = { 0x7d, 0xb5, 0x00 }, + [44] = { 0x00, 0xb5, 0x00 }, + [45] = { 0x00, 0xb5, 0x71 }, + [46] = { 0x00, 0xb5, 0xb5 }, + [47] = { 0x00, 0x63, 0xb5 }, + [48] = { 0x00, 0x00, 0xb5 }, + [49] = { 0x75, 0x00, 0xb5 }, + [50] = { 0xb5, 0x00, 0xb5 }, + [51] = { 0xb5, 0x00, 0x6b }, + [52] = { 0xff, 0x00, 0x00 }, + [53] = { 0xff, 0x8c, 0x00 }, + [54] = { 0xff, 0xff, 0x00 }, + [55] = { 0xb2, 0xff, 0x00 }, + [56] = { 0x00, 0xff, 0x00 }, + [57] = { 0x00, 0xff, 0xa0 }, + [58] = { 0x00, 0xff, 0xff }, + [59] = { 0x00, 0x8c, 0xff }, + [60] = { 0x00, 0x00, 0xff }, + [61] = { 0xa5, 0x00, 0xff }, + [62] = { 0xff, 0x00, 0xff }, + [63] = { 0xff, 0x00, 0x98 }, + [64] = { 0xff, 0x59, 0x59 }, + [65] = { 0xff, 0xb4, 0x59 }, + [66] = { 0xff, 0xff, 0x71 }, + [67] = { 0xcf, 0xff, 0x60 }, + [68] = { 0x6f, 0xff, 0x6f }, + [69] = { 0x65, 0xff, 0xc9 }, + [70] = { 0x6d, 0xff, 0xff }, + [71] = { 0x59, 0xb4, 0xff }, + [72] = { 0x59, 0x59, 0xff }, + [73] = { 0xc4, 0x59, 0xff }, + [74] = { 0xff, 0x66, 0xff }, + [75] = { 0xff, 0x59, 0xbc }, + [76] = { 0xff, 0x9c, 0x9c }, + [77] = { 0xff, 0xd3, 0x9c }, + [78] = { 0xff, 0xff, 0x9c }, + [79] = { 0xe2, 0xff, 0x9c }, + [80] = { 0x9c, 0xff, 0x9c }, + [81] = { 0x9c, 0xff, 0xdb }, + [82] = { 0x9c, 0xff, 0xff }, + [83] = { 0x9c, 0xd3, 0xff }, + [84] = { 0x9c, 0x9c, 0xff }, + [85] = { 0xdc, 0x9c, 0xff }, + [86] = { 0xff, 0x9c, 0xff }, + [87] = { 0xff, 0x94, 0xd3 }, + [88] = { 0x00, 0x00, 0x00 }, + [89] = { 0x13, 0x13, 0x13 }, + [90] = { 0x28, 0x28, 0x28 }, + [91] = { 0x36, 0x36, 0x36 }, + [92] = { 0x4d, 0x4d, 0x4d }, + [93] = { 0x65, 0x65, 0x65 }, + [94] = { 0x81, 0x81, 0x81 }, + [95] = { 0x9f, 0x9f, 0x9f }, + [96] = { 0xbc, 0xbc, 0xbc }, + [97] = { 0xe2, 0xe2, 0xe2 }, + [98] = { 0xff, 0xff, 0xff }, +}; + +rgbcolor* +uirc_ctcp_to_rgb(uint_least8_t color) +{ + if (color < sizeof(rgb_maps) / sizeof(rgbcolor)) return &rgb_maps[color]; + return &rgb_maps[IRC_CTCP_RESET]; +} + +int_least8_t +IRC_CTCP_FORMAT(enum uirc_table_ctcp_formats fmt) +{ + return ctcp_formats[fmt]; +} + +int_least8_t +IRC_CTCP_COLORS(enum uirc_table_ctcp_named_colors col) +{ + return ctcp_named_colors[col]; +} + +// TODO: Write converters for ANSI diff --git a/src/error/error.c b/src/error/error.c index 4884586..e47f79e 100644 --- a/src/error/error.c +++ b/src/error/error.c @@ -16,7 +16,7 @@ * along with uIRC. If not, see . */ -#include "errors.h" +#include "error.h" uirc_errno_t uirc_errno = UIRC_ERR_NERROR; diff --git a/src/memory/list.c b/src/memory/list.c index 0122b63..778e809 100644 --- a/src/memory/list.c +++ b/src/memory/list.c @@ -17,7 +17,6 @@ */ #include "memory.h" -#include "types.h" // IRC_* #include // assert() #include // llist_t diff --git a/src/memory/struct.c b/src/memory/struct.c index 4eda011..c1fb2d7 100644 --- a/src/memory/struct.c +++ b/src/memory/struct.c @@ -16,10 +16,10 @@ * along with uIRC. If not, see . */ -#include "errors.h" // uirc_errno +#include "error.h" // uirc_errno #include "memory.h" -#include "modes.h" // uirc_modes_* -#include "types.h" // IRC_* +#include "mode.h" // uirc_modes_* +#include "type.h" // IRC_* #include // assert() #include // stringext_strmalloc() diff --git a/src/modes/modes.c b/src/mode/mode.c similarity index 85% rename from src/modes/modes.c rename to src/mode/mode.c index 5072adf..01961ac 100644 --- a/src/modes/modes.c +++ b/src/mode/mode.c @@ -16,21 +16,32 @@ * along with uIRC. If not, see . */ -#include "modes.h" +#include "mode.h" #include // assert() #include // isalpha() #include // int_least8_t -#include //ptrdiff_t +#include // bool +#include // ptrdiff_t #if ('b' - 'a' != 1 || 'B' - 'A' != 1 || 'z' - 'a' != 25) #error "System is not US-ASCII." // This is crucial for the conversions below #endif +static const char mode_maps[] = { + [IRC_MODE_WALLOPS] = 'w', [IRC_MODE_INVISIBLE] = 'i', [IRC_MODE_AWAY] = 'a', [IRC_MODE_RESTRICTED] = 'r', + [IRC_MODE_OPERATOR] = 'o', [IRC_MODE_LOCALOPERATOR] = 'O', [IRC_MODE_SERVERNOTICES] = 's', +}; + +char +IRC_MODE(enum uirc_table_mode mode) +{ + return mode_maps[mode]; +} + static int_least8_t uirc_mode_index(char mode) { - assert(mode != NULL); int_least8_t index = 0; if (islower(mode)) { index += mode - 'a'; @@ -94,3 +105,4 @@ uirc_mode_bmconv(IRC_Modes ms) bitmask[i--] = (uirc_mode_fetch(IRC_MODE_INVISIBLE, ms)) ? '1' : '0'; return bitmask; } + diff --git a/src/tag/tag.c b/src/tag/tag.c new file mode 100644 index 0000000..f69cf36 --- /dev/null +++ b/src/tag/tag.c @@ -0,0 +1,32 @@ +/* + * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) + * Copyright (c) 2019-2021 Alex-David Denes + * + * uIRC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * uIRC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with uIRC. If not, see . + */ + +#include "tag.h" + +static const char* const irc_tag[] = { + [IRC_TAG_ACCOUNT] = "account", [IRC_TAG_BATCH] = "batch", [IRC_TAG_BOT] = "bot", + [IRC_TAG_LABEL] = "label", [IRC_TAG_MSGID] = "msgid", [IRC_TAG_MULTILINE] = "multiline-concat", + [IRC_TAG_TIME] = "time", [IRC_TAG_REACT] = "react", [IRC_TAG_REPLY] = "reply", + [IRC_TAG_TYPING] = "typing", +}; + +const char* +IRC_TAG(enum uirc_table_tag tag) +{ + return irc_tag[tag]; +} diff --git a/src/tests/CMakeLists.txt b/src/test/CMakeLists.txt similarity index 100% rename from src/tests/CMakeLists.txt rename to src/test/CMakeLists.txt diff --git a/src/tests/allocs.c b/src/test/allocs.c similarity index 100% rename from src/tests/allocs.c rename to src/test/allocs.c diff --git a/src/tests/common.c b/src/test/common.c similarity index 100% rename from src/tests/common.c rename to src/test/common.c diff --git a/src/tests/common.h b/src/test/common.h similarity index 100% rename from src/tests/common.h rename to src/test/common.h diff --git a/src/tests/earlytrail.c b/src/test/earlytrail.c similarity index 100% rename from src/tests/earlytrail.c rename to src/test/earlytrail.c diff --git a/src/tests/errno.c b/src/test/errno.c similarity index 100% rename from src/tests/errno.c rename to src/test/errno.c diff --git a/src/tests/fullloop.c b/src/test/fullloop.c similarity index 93% rename from src/tests/fullloop.c rename to src/test/fullloop.c index cb9d3f8..325e603 100644 --- a/src/tests/fullloop.c +++ b/src/test/fullloop.c @@ -29,7 +29,10 @@ main(void) { const char* str[] = { ":buddy@hostnet.com PRIVMSG #general :login hunter12\r\n", "NOTICE * :nice cock bro\r\n", - "@day=13;willtolive=0 PRIVMSG you :helo\r\n", +#ifdef UIRC_FEATURE_IRCV3 + "@day=13;willtolive=0 " +#endif /* UIRC_FEATURE_IRCV3 */ + "PRIVMSG you :helo\r\n", ":mom!mother@localhost NOTICE #netadmin :johnny, your pizza is done\r\n", "NOTICE after 14 arguments the trailing starts early so there's no need for a colon hmm interesting really\r\n" }; diff --git a/src/tests/manassm.c b/src/test/manassm.c similarity index 92% rename from src/tests/manassm.c rename to src/test/manassm.c index 4a833ee..cfd79ae 100644 --- a/src/tests/manassm.c +++ b/src/test/manassm.c @@ -31,7 +31,8 @@ int main(void) { IRC_Message* m = uirc_struct_assm_message("NONE", false, 0); - m->tag_list = uirc_list_append(NULL, uirc_struct_assm_tag(false, TAGKEY, TAGVAL)); +#ifdef UIRC_FEATURE_IRCV3 + m->tag_list = uirc_list_append(NULL, uirc_struct_assm_tag(false, TAGKEY, TAGVAL)); uirc_list_append(m->tag_list, uirc_struct_assm_tag(false, TAGKEY2, NULL)); IRC_Tag* t = m->tag_list->next->content; @@ -45,6 +46,7 @@ main(void) fprintf(stderr, "List allocator didn't allocate things right\n"); return EXIT_FAILURE; } +#endif /* UIRC_FEATURE_IRCV3 */ print_irc_message(m); uirc_struct_free(m, IRC_STRUCT_MESSAGE); diff --git a/src/tests/modes.c b/src/test/modes.c similarity index 76% rename from src/tests/modes.c rename to src/test/modes.c index f9396ff..20f9f06 100644 --- a/src/tests/modes.c +++ b/src/test/modes.c @@ -16,7 +16,7 @@ * along with uIRC. If not, see . */ -#include "modes.h" // uirc_mode_*() IRC_Modes +#include "uirc.h" // uirc_mode_*() IRC_Modes #include // fprintf() stderr #include // EXIT_* @@ -25,7 +25,7 @@ int main(void) { IRC_Modes modes, cpymodes; - if (!uirc_mode_enable('a', modes) || !modes[0]) { + if (!uirc_mode_enable(IRC_MODE(IRC_MODE_OPERATOR), modes) || !modes[14]) { fprintf(stderr, "Mode enable didn't work or mode was invalid\n"); return EXIT_FAILURE; } @@ -34,15 +34,15 @@ main(void) return EXIT_FAILURE; } uirc_mode_copy(cpymodes, modes); - if (!cpymodes[0] || !cpymodes[25]) { + if (!cpymodes[14] || !cpymodes[25]) { fprintf(stderr, "Mode copy didn't work\n"); return EXIT_FAILURE; } - if (!uirc_mode_toggle('a', modes) || modes[0]) { + if (!uirc_mode_toggle(IRC_MODE(IRC_MODE_OPERATOR), modes) || modes[14]) { fprintf(stderr, "Mode toggle didn't work or mode was invalid\n"); return EXIT_FAILURE; } - if (!uirc_mode_disable('a', cpymodes) || cpymodes[0]) { + if (!uirc_mode_disable(IRC_MODE(IRC_MODE_OPERATOR), cpymodes) || cpymodes[14]) { fprintf(stderr, "Mode disable didn't work or mode was invalid\n"); return EXIT_FAILURE; } @@ -50,5 +50,9 @@ main(void) fprintf(stderr, "Mode was toggled off incorrectly\n"); return EXIT_FAILURE; } + if (!uirc_mode_disable('A', cpymodes) || cpymodes[25]) { + fprintf(stderr, "Mode disable didn't work or mode was invalid\n"); + return EXIT_FAILURE; + } return EXIT_SUCCESS; } diff --git a/src/tests/optcrlf.c b/src/test/optcrlf.c similarity index 100% rename from src/tests/optcrlf.c rename to src/test/optcrlf.c diff --git a/src/tokenizers/message.c b/src/tokenizer/message.c similarity index 87% rename from src/tokenizers/message.c rename to src/tokenizer/message.c index 6d9b0b6..53beff8 100644 --- a/src/tokenizers/message.c +++ b/src/tokenizer/message.c @@ -16,10 +16,10 @@ * along with uIRC. If not, see . */ -#include "errors.h" // uirc_errno -#include "memory.h" // uirc_memory_*() -#include "tokenizers.h" // uirc_tokenizer_*() -#include "types.h" // IRC_Message +#include "error.h" // uirc_errno +#include "memory.h" // uirc_memory_*() +#include "tokenizer.h" // uirc_tokenizer_*() +#include "type.h" // IRC_Message #include // assert() #include // stringext_strmalloc() stringext_strtok_mr() @@ -110,18 +110,17 @@ uirc_tokenizer_message(const char* str) goto cleanup; } break; - } else { - const char* tmp = NULL; - if ((tmp = stringext_strtok_mr(&p, " ")) == NULL) { - uirc_errno = UIRC_ERR_INVFMT; - goto cleanup; - } - if ((m->args[i++] = stringext_strmalloc(tmp, strlen(tmp))) == NULL) { - uirc_errno = UIRC_ERR_SYSERR; - goto cleanup; - } - skip_spaces(&p); } + const char* tmp = NULL; + if ((tmp = stringext_strtok_mr(&p, " ")) == NULL) { + uirc_errno = UIRC_ERR_INVFMT; + goto cleanup; + } + if ((m->args[i++] = stringext_strmalloc(tmp, strlen(tmp))) == NULL) { + uirc_errno = UIRC_ERR_SYSERR; + goto cleanup; + } + skip_spaces(&p); if (i < IRC_MAXARGS) m->args[i] = NULL; } diff --git a/src/tokenizers/tag.c b/src/tokenizer/tag.c similarity index 94% rename from src/tokenizers/tag.c rename to src/tokenizer/tag.c index a4b4182..ad21e66 100644 --- a/src/tokenizers/tag.c +++ b/src/tokenizer/tag.c @@ -16,10 +16,10 @@ * along with uIRC. If not, see . */ -#include "errors.h" // uirc_errno -#include "memory.h" // Free_IRC_Tag() -#include "tokenizers.h" // uirc_tokenizer_tags() -#include "types.h" // IRC_Tag +#include "error.h" // uirc_errno +#include "memory.h" // Free_IRC_Tag() +#include "tokenizer.h" // uirc_tokenizer_tags() +#include "type.h" // IRC_Tag #include // assert() #include // llist_elem_alloc() llist_elem_conn() llist_elem_rm() diff --git a/src/tokenizers/user.c b/src/tokenizer/user.c similarity index 92% rename from src/tokenizers/user.c rename to src/tokenizer/user.c index 1d2ee94..ef8d8c0 100644 --- a/src/tokenizers/user.c +++ b/src/tokenizer/user.c @@ -16,10 +16,10 @@ * along with uIRC. If not, see . */ -#include "errors.h" // uirc_errno -#include "memory.h" // uirc_memory_*() -#include "tokenizers.h" // uirc_tokenizer_*() -#include "types.h" // IRC_Message +#include "error.h" // uirc_errno +#include "memory.h" // uirc_memory_*() +#include "tokenizer.h" // uirc_tokenizer_*() +#include "type.h" // IRC_Message #include // assert() #include // stringext_strmalloc() diff --git a/src/validators/validators.c b/src/validator/validator.c similarity index 98% rename from src/validators/validators.c rename to src/validator/validator.c index abc1299..80d8d95 100644 --- a/src/validators/validators.c +++ b/src/validator/validator.c @@ -16,7 +16,7 @@ * along with uIRC. If not, see . */ -#include "validators.h" +#include "validator.h" #include // assert() #include // NULL