From a60d0039c140efa302a8f28cc88bbbd5af57a0e8 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sat, 10 Oct 2020 12:30:05 +0200 Subject: [PATCH] Reformat code according to new style --- .clang-format | 3 +- include/functions.h | 2 +- include/helpers.h | 5 ++- include/mappings.h | 2 +- include/types.h | 2 +- include/uirc.h | 8 ++-- src/assemblers.c | 85 +++++++++++++++------------------------- src/assemblers.h | 4 +- src/helpers.c | 48 ++++++++--------------- src/helpers.h | 5 ++- src/misc.c | 94 +++++++++++---------------------------------- src/misc.h | 2 +- src/taghelpers.c | 7 +--- src/taghelpers.h | 2 +- src/tokenizers.c | 53 +++++++++---------------- src/tokenizers.h | 6 +-- src/validators.c | 38 +++++++----------- src/validators.h | 4 +- tests/msgassm.c | 3 +- tests/notrail.c | 3 +- tests/numericmds.c | 3 +- tests/overflow.c | 12 ++++-- tests/prefixassm.c | 5 +-- tests/strtokmr.c | 28 +++++--------- tests/tagassm.c | 4 +- tests/timestamp.c | 3 +- tests/tokenizer.c | 3 +- 27 files changed, 152 insertions(+), 282 deletions(-) diff --git a/.clang-format b/.clang-format index 78ac55d..71b2d6a 100644 --- a/.clang-format +++ b/.clang-format @@ -10,10 +10,11 @@ AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: true AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true +AllowAllParametersOfDeclarationOnNextLine: true BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Linux IndentCaseLabels: true PointerAlignment: Left -ColumnLimit: 0 +ColumnLimit: 150 ... diff --git a/include/functions.h b/include/functions.h index e4725de..ac3628e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "types.h" #include #include diff --git a/include/helpers.h b/include/helpers.h index d6a5259..cbb9fb3 100644 --- a/include/helpers.h +++ b/include/helpers.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "types.h" #include #include @@ -70,7 +70,8 @@ extern IRC_Message* Assm_AUTO(int cmd, bool trailing, char** args, int req); #define Assm_cmd_KICK(channels, users, comment) Assm_AUTO(KICK, true, (char*[]){channels, users, comment, NULL}, 2) #define Assm_cmd_CONNECT(target, port, remote) Assm_AUTO(CONNECT, false, (char*[]){target, port, remote, NULL}, 2) -#define Assm_cmd_SERVICE(nickname, distribution, type, info) Assm_AUTO(SERVICE, true, (char*[]){nickname, RESERVED, distribution, "0", RESERVED, info, NULL}, 6) +#define Assm_cmd_SERVICE(nickname, distribution, type, info) \ + Assm_AUTO(SERVICE, true, (char*[]){nickname, RESERVED, distribution, "0", RESERVED, info, NULL}, 6) extern IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes); extern IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask); diff --git a/include/mappings.h b/include/mappings.h index 7af7d96..ef48545 100644 --- a/include/mappings.h +++ b/include/mappings.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #ifndef UIRC_INCLUDED_ENUMS #define UIRC_INCLUDED_ENUMS diff --git a/include/types.h b/include/types.h index 377b2b4..e72fdef 100644 --- a/include/types.h +++ b/include/types.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include #ifndef UIRC_INCLUDED_TYPES diff --git a/include/uirc.h b/include/uirc.h index 9f97aa9..414d159 100644 --- a/include/uirc.h +++ b/include/uirc.h @@ -14,12 +14,12 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ -#include "helpers.h" -#include "types.h" -#include "mappings.h" #include "functions.h" +#include "helpers.h" +#include "mappings.h" +#include "types.h" #ifndef UIRC_INCLUDED #define UIRC_INCLUDED diff --git a/src/assemblers.c b/src/assemblers.c index 6bea7f4..c68e83f 100644 --- a/src/assemblers.c +++ b/src/assemblers.c @@ -14,13 +14,12 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "assemblers.h" signed long Assm_mesg(char* buf, IRC_Message* in, size_t len) { - if (buf == NULL || in == NULL) - return ERR_UIRC_BUFFER_ERR; + if (buf == NULL || in == NULL) return ERR_UIRC_BUFFER_ERR; char* pos = buf; signed long cnt, ret; #ifdef UIRC_IRCV3 @@ -28,19 +27,16 @@ signed long Assm_mesg(char* buf, IRC_Message* in, size_t len) return ret; else if (ret != 0) { pos += ret; - if (!safe_charcpy(&pos, ' ', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, ' ', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } #endif if (in->name.nick != NULL || in->name.host != NULL) { - if (!safe_charcpy(&pos, ':', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, ':', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; if ((ret = Assm_user(pos, &in->name, len - (unsigned long)(pos - buf), false)) <= 0) return ret; else pos += ret; - if (!safe_charcpy(&pos, ' ', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, ' ', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } if (in->cmd < UIRC_FCMD || in->cmd > UIRC_LCMD) { if ((cnt = snprintf(pos, 4, "%.3i", in->cmd)) == 3) @@ -57,52 +53,42 @@ signed long Assm_mesg(char* buf, IRC_Message* in, size_t len) } } for (unsigned int i = 0; in->args[i] != NULL; i++) { - if (len - (unsigned long)(pos - buf) > strlen(in->args[i]) + 2 && (cnt = snprintf(pos, len - (unsigned long)(pos - buf), (in->args[i + 1] == NULL && in->trailing) ? " :%s" : " %s", in->args[i])) > 0) + if (len - (unsigned long)(pos - buf) > strlen(in->args[i]) + 2 + && (cnt = + snprintf(pos, len - (unsigned long)(pos - buf), (in->args[i + 1] == NULL && in->trailing) ? " :%s" : " %s", in->args[i])) + > 0) pos += cnt; else return ERR_UIRC_BUFFER_ERR; } - if (!safe_strcpy(&pos, "\r\n", len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, "\r\n", len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; return pos - buf; } #ifdef UIRC_IRCV3 signed long Assm_tags(char* buf, IRC_Tags* in, size_t len) { - if (buf == NULL || in == NULL) - return ERR_UIRC_NULL_ARGS; + if (buf == NULL || in == NULL) return ERR_UIRC_NULL_ARGS; char* pos = buf; - struct tagmapping tagmps[] = { - {.name = "time", .assg = &in->time}, - {.name = "account", .assg = &in->account}, - {.name = "batch", .assg = &in->batch}, - {.name = "label", .assg = &in->label}, - {.name = "msgid", .assg = &in->msgid}, - {.name = "multiline-concat", .assg = &in->multiline_concat}, - {.name = "typing", .assg = &in->typing}, - {.name = "react", .assg = &in->react}, - {.name = "reply", .assg = &in->reply}}; + struct tagmapping tagmps[] = {{.name = "time", .assg = &in->time}, {.name = "account", .assg = &in->account}, + {.name = "batch", .assg = &in->batch}, {.name = "label", .assg = &in->label}, + {.name = "msgid", .assg = &in->msgid}, {.name = "multiline-concat", .assg = &in->multiline_concat}, + {.name = "typing", .assg = &in->typing}, {.name = "react", .assg = &in->react}, + {.name = "reply", .assg = &in->reply}}; for (unsigned int i = 0; i < sizeof(tagmps) / sizeof(struct tagmapping); i++) { if ((*tagmps[i].assg).value != NULL) { if (pos == buf) { - if (!safe_charcpy(&pos, '@', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '@', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } else { - if (!safe_charcpy(&pos, ';', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, ';', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } if ((*tagmps[i].assg).clientbound) { - if (!safe_charcpy(&pos, '+', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '+', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } - if (!safe_strcpy(&pos, tagmps[i].name, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, tagmps[i].name, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; if (*(*tagmps[i].assg).value != '\0') { - if (!safe_charcpy(&pos, '=', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; - if (!safe_strcpy(&pos, (*tagmps[i].assg).value, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '=', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, (*tagmps[i].assg).value, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } } } @@ -112,32 +98,23 @@ signed long Assm_tags(char* buf, IRC_Tags* in, size_t len) signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig) { - if (buf == NULL || in == NULL) - return ERR_UIRC_NULL_ARGS; + if (buf == NULL || in == NULL) return ERR_UIRC_NULL_ARGS; char* pos = buf; if (in->nick == NULL && in->host != NULL) { - if (!safe_strcpy(&pos, in->host, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, in->host, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } else if (in->nick != NULL) { - if (!safe_strcpy(&pos, in->nick, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, in->nick, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; if (in->user != NULL) { - if (!safe_charcpy(&pos, '!', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; - if (!safe_strcpy(&pos, in->user, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '!', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, in->user, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } if (useorig && in->orig != NULL) { - if (!safe_charcpy(&pos, '%', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; - if (!safe_strcpy(&pos, in->orig, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '%', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, in->orig, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } if (in->host != NULL) { - if (!safe_charcpy(&pos, '@', len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; - if (!safe_strcpy(&pos, in->host, len - (unsigned long)(pos - buf))) - return ERR_UIRC_BUFFER_ERR; + if (!safe_charcpy(&pos, '@', len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; + if (!safe_strcpy(&pos, in->host, len - (unsigned long)(pos - buf))) return ERR_UIRC_BUFFER_ERR; } } else return ERR_UIRC_NULL_ARGS; diff --git a/src/assemblers.h b/src/assemblers.h index 9ad5707..a774127 100644 --- a/src/assemblers.h +++ b/src/assemblers.h @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ -#include "../include/types.h" #include "../include/mappings.h" +#include "../include/types.h" #include "misc.h" #include #include diff --git a/src/helpers.c b/src/helpers.c index 4446f61..426cc51 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -14,25 +14,19 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "helpers.h" static IRC_Message imassm_mesg; char* RESERVED = "*"; -void clear_assm(void) -{ - memset((void*)&imassm_mesg, '\0', sizeof(IRC_Message)); -} +void clear_assm(void) { memset((void*)&imassm_mesg, '\0', sizeof(IRC_Message)); } IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req) { clear_assm(); int i; - for (i = 0; args[i] != NULL && i < 15; i++) { - imassm_mesg.args[i] = args[i]; - } - if (i < req) - return NULL; + for (i = 0; args[i] != NULL && i < 15; i++) { imassm_mesg.args[i] = args[i]; } + if (i < req) return NULL; imassm_mesg.trailing = trailing; imassm_mesg.cmd = cmd; return &imassm_mesg; @@ -40,8 +34,7 @@ IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req) IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes) { - if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS)) - return NULL; + if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS)) return NULL; clear_assm(); static char local_mode[2]; snprintf(local_mode, 2, "%i", modes); @@ -56,8 +49,7 @@ IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes) IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask) { - if (remoteserv != NULL && servmask == NULL) - return NULL; + if (remoteserv != NULL && servmask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (remoteserv == NULL) ? servmask : remoteserv; imassm_mesg.args[1] = (remoteserv == NULL) ? NULL : servmask; @@ -68,8 +60,7 @@ IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask) IRC_Message* Assm_cmd_WHO(char* mask, bool oper) { static char* operator= "o"; - if (oper && mask == NULL) - return NULL; + if (oper && mask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = mask; imassm_mesg.args[1] = (oper) ? operator: NULL; @@ -79,8 +70,7 @@ IRC_Message* Assm_cmd_WHO(char* mask, bool oper) IRC_Message* Assm_cmd_WHOIS(char* target, char* mask) { - if (mask == NULL) - return NULL; + if (mask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (target == NULL) ? mask : target; imassm_mesg.args[1] = (target == NULL) ? NULL : mask; @@ -90,8 +80,7 @@ IRC_Message* Assm_cmd_WHOIS(char* target, char* mask) IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target) { - if (nick == NULL || (target != NULL && count == NULL)) - return NULL; + if (nick == NULL || (target != NULL && count == NULL)) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.args[1] = count; @@ -105,8 +94,7 @@ IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target) */ IRC_Message* Assm_cmd_PING(char* source, char* target) { - if (source == NULL && target == NULL) - return NULL; + if (source == NULL && target == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (source != NULL) ? source : target; imassm_mesg.args[1] = (source != NULL && target != NULL) ? target : NULL; @@ -117,8 +105,7 @@ IRC_Message* Assm_cmd_PING(char* source, char* target) IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel) { - if (user == NULL || (channel != NULL && target == NULL)) - return NULL; + if (user == NULL || (channel != NULL && target == NULL)) return NULL; clear_assm(); imassm_mesg.args[0] = user; imassm_mesg.args[1] = target; @@ -128,23 +115,18 @@ IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel) } IRC_Message* Assm_cmd_USERHOST(char* users[]) { - if (users[0] == NULL) - return NULL; + if (users[0] == NULL) return NULL; clear_assm(); - for (unsigned int i = 0; i < 5 && users[i] != NULL; i++) - imassm_mesg.args[i] = users[i]; + for (unsigned int i = 0; i < 5 && users[i] != NULL; i++) imassm_mesg.args[i] = users[i]; imassm_mesg.cmd = USERHOST; return &imassm_mesg; } /* NOTE: Limited to 14 nicks per command */ IRC_Message* Assm_cmd_ISON(char* users[]) { - if (users[0] == NULL) - return NULL; + if (users[0] == NULL) return NULL; clear_assm(); - for (unsigned int i = 0; i < 14 && users[i] != NULL; i++) { - imassm_mesg.args[i] = users[i]; - } + for (unsigned int i = 0; i < 14 && users[i] != NULL; i++) { imassm_mesg.args[i] = users[i]; } imassm_mesg.cmd = ISON; return &imassm_mesg; } diff --git a/src/helpers.h b/src/helpers.h index 4fc2667..513a935 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "../include/mappings.h" #include "../include/types.h" @@ -76,7 +76,8 @@ IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req); #define Assm_cmd_KICK(channels, users, comment) Assm_AUTO(KICK, true, (char*[]){channels, users, comment, NULL}, 2) #define Assm_cmd_CONNECT(target, port, remote) Assm_AUTO(CONNECT, false, (char*[]){target, port, remote, NULL}, 2) -#define Assm_cmd_SERVICE(nickname, distribution, type, info) Assm_AUTO(SERVICE, true, (char*[]){nickname, RESERVED, distribution, "0", RESERVED, info, NULL}, 6) +#define Assm_cmd_SERVICE(nickname, distribution, type, info) \ + Assm_AUTO(SERVICE, true, (char*[]){nickname, RESERVED, distribution, "0", RESERVED, info, NULL}, 6) IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes); IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask); diff --git a/src/misc.c b/src/misc.c index 86ff1dd..ea3604a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -14,82 +14,34 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "misc.h" -const char* const IRC_Cmds[] = { - [ADMIN] = "ADMIN", - [AWAY] = "AWAY", - [CONNECT] = "CONNECT", - [DIE] = "DIE", - [ERROR] = "ERROR", - [INFO] = "INFO", - [INVITE] = "INVITE", - [ISON] = "ISON", - [JOIN] = "JOIN", - [KICK] = "KICK", - [KILL] = "KILL", - [LINKS] = "LINKS", - [LIST] = "LIST", - [LUSERS] = "LUSERS", - [MODE] = "MODE", - [MOTD] = "MOTD", - [NAMES] = "NAMES", - [NICK] = "NICK", - [NOTICE] = "NOTICE", - [OPER] = "OPER", - [PART] = "PART", - [PASS] = "PASS", - [PING] = "PING", - [PONG] = "PONG", - [PRIVMSG] = "PRIVMSG", - [QUIT] = "QUIT", - [REHASH] = "REHASH", - [RESTART] = "RESTART", - [SERVER] = "SERVER", - [SERVICE] = "SERVICE", - [SERVLIST] = "SERVLIST", - [SQUERY] = "SQUERY", - [SQUIT] = "SQUIT", - [STATS] = "STATS", - [SUMMON] = "SUMMON", - [TIME] = "TIME", - [TOPIC] = "TOPIC", - [TRACE] = "TRACE", - [USERHOST] = "USERHOST", - [USERS] = "USERS", - [USER] = "USER", - [VERSION] = "VERSION", - [WALLOPS] = "WALLOPS", - [WHOIS] = "WHOIS", - [WHOWAS] = "WHOWAS", - [WHO] = "WHO", +const char* const IRC_Cmds[] = {[ADMIN] = "ADMIN", [AWAY] = "AWAY", [CONNECT] = "CONNECT", [DIE] = "DIE", + [ERROR] = "ERROR", [INFO] = "INFO", [INVITE] = "INVITE", [ISON] = "ISON", + [JOIN] = "JOIN", [KICK] = "KICK", [KILL] = "KILL", [LINKS] = "LINKS", + [LIST] = "LIST", [LUSERS] = "LUSERS", [MODE] = "MODE", [MOTD] = "MOTD", + [NAMES] = "NAMES", [NICK] = "NICK", [NOTICE] = "NOTICE", [OPER] = "OPER", + [PART] = "PART", [PASS] = "PASS", [PING] = "PING", [PONG] = "PONG", + [PRIVMSG] = "PRIVMSG", [QUIT] = "QUIT", [REHASH] = "REHASH", [RESTART] = "RESTART", + [SERVER] = "SERVER", [SERVICE] = "SERVICE", [SERVLIST] = "SERVLIST", [SQUERY] = "SQUERY", + [SQUIT] = "SQUIT", [STATS] = "STATS", [SUMMON] = "SUMMON", [TIME] = "TIME", + [TOPIC] = "TOPIC", [TRACE] = "TRACE", [USERHOST] = "USERHOST", [USERS] = "USERS", + [USER] = "USER", [VERSION] = "VERSION", [WALLOPS] = "WALLOPS", [WHOIS] = "WHOIS", + [WHOWAS] = "WHOWAS", [WHO] = "WHO", #ifdef UIRC_IRCV3 - [ACCOUNT] = "ACCOUNT", - [ACC] = "ACC", - [ACK] = "ACK", - [AUTHENTICATE] = "AUTHENTICATE", - [BATCH] = "BATCH", - [CAP] = "CAP", - [CHGHOST] = "CHGHOST", - [FAIL] = "FAIL", - [MONITOR] = "MONITOR", - [NOTE] = "NOTE", - [RENAME] = "RENAME", - [RESUME] = "RESUME", - [SETNAME] = "SETNAME", - [WARN] = "WARN", - [WEBIRC] = "WEBIRC" + [ACCOUNT] = "ACCOUNT", [ACC] = "ACC", [ACK] = "ACK", [AUTHENTICATE] = "AUTHENTICATE", + [BATCH] = "BATCH", [CAP] = "CAP", [CHGHOST] = "CHGHOST", [FAIL] = "FAIL", + [MONITOR] = "MONITOR", [NOTE] = "NOTE", [RENAME] = "RENAME", [RESUME] = "RESUME", + [SETNAME] = "SETNAME", [WARN] = "WARN", [WEBIRC] = "WEBIRC" #endif }; signed short Ircmd_stoi(char* str) { - if (str == NULL) - return ERR_UIRC_NULL_ARGS; - for (signed short i = UIRC_FCMD; i <= (signed short) UIRC_LCMD; i++) { - if (IRC_Cmds[i] != NULL && strcmp(IRC_Cmds[i], str) == 0) - return i; + if (str == NULL) return ERR_UIRC_NULL_ARGS; + for (signed short i = UIRC_FCMD; i <= (signed short)UIRC_LCMD; i++) { + if (IRC_Cmds[i] != NULL && strcmp(IRC_Cmds[i], str) == 0) return i; } return ERR_UIRC_UNKNOWN_TOKEN; } @@ -123,13 +75,11 @@ void skip_spaces(char** addr) char* strtok_mr(char** addr, const char* tokens) { - if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) - return NULL; + if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) return NULL; char* save = *addr; const char* tok = NULL; do { - if (!**addr) - return save; + if (!**addr) return save; for (tok = tokens; *tok; tok++) { if (**addr == *tok) { **addr = '\0'; diff --git a/src/misc.h b/src/misc.h index 12987a0..39e67e3 100644 --- a/src/misc.h +++ b/src/misc.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "../include/mappings.h" #include "../include/types.h" diff --git a/src/taghelpers.c b/src/taghelpers.c index 7a14b1d..e1d9319 100644 --- a/src/taghelpers.c +++ b/src/taghelpers.c @@ -14,12 +14,9 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "taghelpers.h" -size_t Assm_tag_timestamp(char* buf, size_t len, time_t time) -{ - return strftime(buf, len, "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&time)); -} +size_t Assm_tag_timestamp(char* buf, size_t len, time_t time) { return strftime(buf, len, "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&time)); } diff --git a/src/taghelpers.h b/src/taghelpers.h index 7f86b9d..a04e5fe 100644 --- a/src/taghelpers.h +++ b/src/taghelpers.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include #include diff --git a/src/tokenizers.c b/src/tokenizers.c index 01234fd..13f40fc 100644 --- a/src/tokenizers.c +++ b/src/tokenizers.c @@ -14,21 +14,19 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "tokenizers.h" signed int Tok_mesg(char* str, IRC_Message* out) { - if (str == NULL || out == NULL) - return ERR_UIRC_NULL_ARGS; + if (str == NULL || out == NULL) return ERR_UIRC_NULL_ARGS; int ret; char *progr = str, *command; #ifdef UIRC_IRCV3 if (*progr == '@') { char* tags; if ((tags = strtok_mr(&progr, " ")) != NULL) { - if ((ret = Tok_tags(tags, &out->tags)) < 0) - return ret; + if ((ret = Tok_tags(tags, &out->tags)) < 0) return ret; } else return ERR_UIRC_INVALID_FORMAT; } @@ -37,8 +35,7 @@ signed int Tok_mesg(char* str, IRC_Message* out) if (*progr == ':') { char* prefix; if ((prefix = strtok_mr(&progr, " ")) != NULL) { - if ((ret = Tok_user(prefix, &out->name, false)) < 0) - return ret; + if ((ret = Tok_user(prefix, &out->name, false)) < 0) return ret; } else return ERR_UIRC_INVALID_FORMAT; } @@ -48,8 +45,7 @@ signed int Tok_mesg(char* str, IRC_Message* out) if ((command = strtok_mr(&progr, " ")) != NULL) { signed short temp; if (isalpha(*command)) { - if ((temp = Ircmd_stoi(command)) < UIRC_FCMD || temp > UIRC_LCMD) - return ERR_UIRC_UNKNOWN_TOKEN; + if ((temp = Ircmd_stoi(command)) < UIRC_FCMD || temp > UIRC_LCMD) return ERR_UIRC_UNKNOWN_TOKEN; out->cmd = (IRC_Command)temp; } else { out->cmd = (IRC_Command)atoi(command); @@ -66,8 +62,7 @@ signed int Tok_mesg(char* str, IRC_Message* out) out->trailing = true; break; } else { - if ((out->args[i++] = strtok_mr(&progr, " ")) == NULL) - return ERR_UIRC_INVALID_FORMAT; + if ((out->args[i++] = strtok_mr(&progr, " ")) == NULL) return ERR_UIRC_INVALID_FORMAT; skip_spaces(&progr); } } @@ -78,30 +73,22 @@ signed int Tok_mesg(char* str, IRC_Message* out) #ifdef UIRC_IRCV3 signed int Tok_tags(char* str, IRC_Tags* out) { - if (str == NULL || out == NULL) - return ERR_UIRC_NULL_ARGS; + if (str == NULL || out == NULL) return ERR_UIRC_NULL_ARGS; char *cval, *cpos = str, *ctag = NULL; bool clientbound; - const struct tagmapping tagmps[] = { - {.name = "time", .assg = &out->time}, - {.name = "account", .assg = &out->account}, - {.name = "batch", .assg = &out->batch}, - {.name = "label", .assg = &out->label}, - {.name = "msgid", .assg = &out->msgid}, - {.name = "multiline-concat", .assg = &out->multiline_concat}, - {.name = "typing", .assg = &out->typing}, - {.name = "react", .assg = &out->react}, - {.name = "reply", .assg = &out->reply}}; - if (*cpos == '@') - cpos++; + const struct tagmapping tagmps[] = {{.name = "time", .assg = &out->time}, {.name = "account", .assg = &out->account}, + {.name = "batch", .assg = &out->batch}, {.name = "label", .assg = &out->label}, + {.name = "msgid", .assg = &out->msgid}, {.name = "multiline-concat", .assg = &out->multiline_concat}, + {.name = "typing", .assg = &out->typing}, {.name = "react", .assg = &out->react}, + {.name = "reply", .assg = &out->reply}}; + if (*cpos == '@') cpos++; while ((ctag = strtok_mr(&cpos, "; ")) != NULL) { clientbound = false; if (*ctag == '+') { ctag++; clientbound = true; } - if ((cval = strchr(ctag, '=')) != NULL) - *(cval++) = '\0'; + if ((cval = strchr(ctag, '=')) != NULL) *(cval++) = '\0'; for (unsigned int i = 0; i < sizeof(tagmps) / sizeof(struct tagmapping); i++) { if (!strcmp(ctag, tagmps[i].name)) { /* If the tag is present we point it to the value if given, or to the delimiter ('\0') @@ -120,14 +107,12 @@ signed int Tok_tags(char* str, IRC_Tags* out) signed int Tok_user(char* str, IRC_User* out, bool useorig) { char* pos = (*str == ':') ? str + 1 : str; - if ((out->host = strchr(pos, '@')) != NULL) - *(out->host++) = '\0'; - if (useorig && (out->orig = strchr(pos, '%')) != NULL) - *(out->orig++) = '\0'; - if ((out->user = strchr(pos, '!')) != NULL) /* RFC2812 says this cannot be here without the host but RFC1459 says it can, we accept both options */ + if ((out->host = strchr(pos, '@')) != NULL) *(out->host++) = '\0'; + if (useorig && (out->orig = strchr(pos, '%')) != NULL) *(out->orig++) = '\0'; + if ((out->user = strchr(pos, '!')) + != NULL) /* RFC2812 says this cannot be here without the host but RFC1459 says it can, we accept both options */ *((char*)out->user++) = '\0'; - if (!*(out->nick = pos)) - return ERR_UIRC_INVALID_FORMAT; + if (!*(out->nick = pos)) return ERR_UIRC_INVALID_FORMAT; /* NOTE: De-facto standard below * This assumes that every prefix without a '@host' and '!user' is itself a host prefix only * It might be a actual nickname, but this is the most common around every network diff --git a/src/tokenizers.h b/src/tokenizers.h index 794d1cb..3d9c9e8 100644 --- a/src/tokenizers.h +++ b/src/tokenizers.h @@ -14,15 +14,15 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ -#include "../include/types.h" #include "../include/mappings.h" +#include "../include/types.h" #include "misc.h" +#include #include #include #include -#include #ifndef UIRC_INCLUDED_TKNIZ #define UIRC_INCLUDED_TKNIZ diff --git a/src/validators.c b/src/validators.c index bd43f28..3803baa 100644 --- a/src/validators.c +++ b/src/validators.c @@ -15,19 +15,16 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ #include "validators.h" signed int Val_mesg(IRC_Message* mesg) { - if (mesg == NULL) - return ERR_UIRC_NULL_ARGS; + if (mesg == NULL) return ERR_UIRC_NULL_ARGS; for (unsigned int i = 0; mesg->args[i] != NULL; i++) { - if (Val_type_nocrlf(mesg->args[i]) != 1) - return ERR_UIRC_VAL_FAILED; + if (Val_type_nocrlf(mesg->args[i]) != 1) return ERR_UIRC_VAL_FAILED; if (!(mesg->args[i + 1] == NULL && mesg->trailing)) { - if (Val_type_nospcl(mesg->args[i]) != 1) - return ERR_UIRC_VAL_FAILED; + if (Val_type_nospcl(mesg->args[i]) != 1) return ERR_UIRC_VAL_FAILED; } } return 1; @@ -35,43 +32,35 @@ signed int Val_mesg(IRC_Message* mesg) signed int Val_type_nocrlf(char* str) { - if (str == NULL) - return ERR_UIRC_NULL_ARGS; + if (str == NULL) return ERR_UIRC_NULL_ARGS; for (; *str; str++) { - if (*str == '\r' || *str == '\n') - return 0; + if (*str == '\r' || *str == '\n') return 0; } return 1; } signed int Val_type_nospcl(char* str) { - if (str == NULL) - return ERR_UIRC_NULL_ARGS; + if (str == NULL) return ERR_UIRC_NULL_ARGS; for (; *str; str++) { - if (*str == ' ' || *str == ':') - return 0; + if (*str == ' ' || *str == ':') return 0; } return 1; } signed int Val_type_noblcm(char* str) { - if (str == NULL) - return ERR_UIRC_NULL_ARGS; + if (str == NULL) return ERR_UIRC_NULL_ARGS; for (; *str; str++) { - if (*str == '\a' || *str == ',') - return 0; + if (*str == '\a' || *str == ',') return 0; } return 1; } signed int Val_channame(char* chan) { - if (chan == NULL) - return ERR_UIRC_NULL_ARGS; - if (*chan != '#' && *chan != '+' && *chan != '!' && *chan != '&') - return 0; + if (chan == NULL) return ERR_UIRC_NULL_ARGS; + if (*chan != '#' && *chan != '+' && *chan != '!' && *chan != '&') return 0; char* clps = ++chan; if ((clps = strchr(chan, ':')) != NULL) { *clps = '\0'; @@ -82,8 +71,7 @@ signed int Val_channame(char* chan) *clps = ':'; chan = ++clps; } - if (Val_type_nospcl(chan) != 1 || Val_type_nocrlf(chan) != 1 || Val_type_noblcm(chan) != 1) - return 0; + if (Val_type_nospcl(chan) != 1 || Val_type_nocrlf(chan) != 1 || Val_type_noblcm(chan) != 1) return 0; return 1; } diff --git a/src/validators.h b/src/validators.h index 06b2b37..9593e3b 100644 --- a/src/validators.h +++ b/src/validators.h @@ -14,10 +14,10 @@ * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . -*/ + */ -#include "../include/types.h" #include "../include/mappings.h" +#include "../include/types.h" #include #include diff --git a/tests/msgassm.c b/tests/msgassm.c index 4c2cc8c..a2483ab 100644 --- a/tests/msgassm.c +++ b/tests/msgassm.c @@ -8,8 +8,7 @@ int main(void) char mesg[513] = {0}; IRC_Message input = { #ifdef UIRC_IRCV3 - .tags = { - .msgid = {.value = "10"}}, + .tags = {.msgid = {.value = "10"}}, #endif .name = {.nick = "dad", .user = "dad-door", .host = "home.localhost"}, .cmd = PRIVMSG, diff --git a/tests/notrail.c b/tests/notrail.c index f3e3470..6d6d630 100644 --- a/tests/notrail.c +++ b/tests/notrail.c @@ -5,8 +5,7 @@ int main(void) { - char mesg[513] = - ":nick!user@host QUIT arg1 "; + char mesg[513] = ":nick!user@host QUIT arg1 "; IRC_Message parseout = {0}; int res = 0; if ((res = Tok_mesg(mesg, &parseout)) <= 0) { diff --git a/tests/numericmds.c b/tests/numericmds.c index f74d6f2..bc9c061 100644 --- a/tests/numericmds.c +++ b/tests/numericmds.c @@ -16,8 +16,7 @@ int main(void) printf("Failed to assemble message. (%li)\n", res); return EXIT_FAILURE; } - char* expect = - "001 :hello\r\n"; + char* expect = "001 :hello\r\n"; if (strcmp(expect, mesg) != 0) { printf("Assembled message mismatch.\nGot:\n%s\nbut expected:\n%s\n", mesg, expect); return EXIT_FAILURE; diff --git a/tests/overflow.c b/tests/overflow.c index c8f9b6f..8bf2f26 100644 --- a/tests/overflow.c +++ b/tests/overflow.c @@ -8,10 +8,16 @@ int main(void) char mesg[513] = {0}; IRC_Message input = { .cmd = NOTICE, - .args = {"*", "Cock and ball torture (CBT), penis torture or dick torture is a sexual activity involving application of pain or constriction to the penis or testicles. This may involve directly painful activities, such as genital piercing, wax play, genital spanking, squeezing, ball-busting, genital flogging, urethral play, tickle torture, erotic electrostimulation, kneeing or kicking. The recipient of such activities may receive direct physical pleasure via masochism, or emotional pleasure through erotic humiliation, or knowledge that the play is pleasing to a sadistic dominant. Many of these practices carry significant health risks.", NULL}, + .args = + {"*", + "Cock and ball torture (CBT), penis torture or dick torture is a sexual activity involving application of pain or constriction to " + "the penis or testicles. This may involve directly painful activities, such as genital piercing, wax play, genital spanking, " + "squeezing, ball-busting, genital flogging, urethral play, tickle torture, erotic electrostimulation, kneeing or kicking. The " + "recipient of such activities may receive direct physical pleasure via masochism, or emotional pleasure through erotic humiliation, " + "or knowledge that the play is pleasing to a sadistic dominant. Many of these practices carry significant health risks.", + NULL}, .trailing = true}; - if (Assm_mesg(mesg, &input, 512) > 0) - return EXIT_FAILURE; + if (Assm_mesg(mesg, &input, 512) > 0) return EXIT_FAILURE; return EXIT_SUCCESS; } diff --git a/tests/prefixassm.c b/tests/prefixassm.c index c01814b..601c986 100644 --- a/tests/prefixassm.c +++ b/tests/prefixassm.c @@ -6,10 +6,7 @@ int main(void) { char mesg[513] = {0}; - IRC_User input = { - .nick = "durov", - .user = "pavel", - .host = "telegram.org"}; + IRC_User input = {.nick = "durov", .user = "pavel", .host = "telegram.org"}; signed long res = 0; if ((res = Assm_user(mesg, &input, 512, false)) <= 0) { printf("String could not be assembled. %li\n", res); diff --git a/tests/strtokmr.c b/tests/strtokmr.c index 5fa06d0..73108ca 100644 --- a/tests/strtokmr.c +++ b/tests/strtokmr.c @@ -6,36 +6,28 @@ int main(void) { char* pointer = NULL; - if (strtok_mr(&pointer, "!") != NULL) - return EXIT_FAILURE; - if (pointer != NULL) - return EXIT_FAILURE; + if (strtok_mr(&pointer, "!") != NULL) return EXIT_FAILURE; + if (pointer != NULL) return EXIT_FAILURE; char test2[] = "hello"; pointer = test2; - if (strtok_mr(&pointer, "!") == NULL) - return EXIT_FAILURE; - if (*pointer != '\0') - return EXIT_FAILURE; + if (strtok_mr(&pointer, "!") == NULL) return EXIT_FAILURE; + if (*pointer != '\0') return EXIT_FAILURE; char test3[] = "hi!# hello!"; pointer = test3; - if (strtok_mr(&pointer, "!#") == NULL) - return EXIT_FAILURE; - if (pointer != test3+3) /* MUST point at # right after ! */ + if (strtok_mr(&pointer, "!#") == NULL) return EXIT_FAILURE; + if (pointer != test3 + 3) /* MUST point at # right after ! */ return EXIT_FAILURE; if (test3[2] != '\0') /* MUST replace ! with \0 */ return EXIT_FAILURE; - if (strtok_mr(&pointer, "!#") == NULL) - return EXIT_FAILURE; - if (pointer != test3+4) /* MUST point at whitespace right after # */ + if (strtok_mr(&pointer, "!#") == NULL) return EXIT_FAILURE; + if (pointer != test3 + 4) /* MUST point at whitespace right after # */ return EXIT_FAILURE; if (test3[3] != '\0') /* MUST replace # with \0 */ return EXIT_FAILURE; - if (strtok_mr(&pointer, "!#") == NULL) - return EXIT_FAILURE; - if (strtok_mr(&pointer, "!#") != NULL) - return EXIT_FAILURE; + if (strtok_mr(&pointer, "!#") == NULL) return EXIT_FAILURE; + if (strtok_mr(&pointer, "!#") != NULL) return EXIT_FAILURE; return EXIT_SUCCESS; } diff --git a/tests/tagassm.c b/tests/tagassm.c index ed5ead7..f66d7dd 100644 --- a/tests/tagassm.c +++ b/tests/tagassm.c @@ -6,9 +6,7 @@ int main(void) { char mesg[513] = {0}; - IRC_Tags input = { - .time = {.value = "now", .clientbound = true}, - .msgid = {.value = "", .clientbound = false}}; + IRC_Tags input = {.time = {.value = "now", .clientbound = true}, .msgid = {.value = "", .clientbound = false}}; signed long res = 0; if ((res = Assm_tags(mesg, &input, 512)) <= 0) { printf("String could not be assembled. %li\n", res); diff --git a/tests/timestamp.c b/tests/timestamp.c index e096ab4..88545e0 100644 --- a/tests/timestamp.c +++ b/tests/timestamp.c @@ -8,8 +8,7 @@ int main(void) { char buffer[26]; time_t res = 1130620230; - if (Assm_tag_timestamp(buffer, sizeof(buffer), res)) - printf("Time is: %s\n", buffer); + if (Assm_tag_timestamp(buffer, sizeof(buffer), res)) printf("Time is: %s\n", buffer); return EXIT_SUCCESS; } diff --git a/tests/tokenizer.c b/tests/tokenizer.c index 7e3414a..a59c8b4 100644 --- a/tests/tokenizer.c +++ b/tests/tokenizer.c @@ -15,8 +15,7 @@ int main(void) "@+msgid=1s32;time;+reply;account=x " #endif ":" nickname "!" username "@" hostname " QUIT arg1 :" arg2, - "001 hell :sup cj" - }; + "001 hell :sup cj"}; IRC_Message parseout = {0}; int res = 0; if ((res = Tok_mesg(mesg[0], &parseout)) <= 0) {