Reformat code, add if preprocessor comments, shorten structrs, remove analyzer

This commit is contained in:
Alex D. 2020-12-16 14:22:25 +00:00
parent 124da1eb77
commit 0d019b02dc
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
19 changed files with 502 additions and 446 deletions

View File

@ -1,20 +1,41 @@
---
Language: Cpp
Standard: Cpp11
BasedOnStyle: LLVM
TabWidth: 8
IndentWidth: 8
UseTab: ForIndentation
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
AlignEscapedNewlines: Left
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLoopsOnASingleLine: 'true'
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: 'false'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Linux
IndentCaseLabels: true
BreakStringLiterals: 'false'
ColumnLimit: '150'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
Cpp11BracedListStyle: 'false'
IncludeBlocks: Regroup
IndentCaseLabels: 'true'
IndentPPDirectives: None
IndentWidth: '8'
Language: Cpp
PointerAlignment: Left
ColumnLimit: 150
...
ReflowComments: 'true'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeParens: ControlStatements
SpacesInCStyleCastParentheses: 'false'
Standard: Cpp11
TabWidth: '8'
UseTab: ForIndentation
...

View File

@ -1,9 +1,9 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-core.*,clang-analyzer-optin.performance.*,clang-analyzer-optin.portability.*,clang-analyzer-nullability.*,clang-analyzer-security.*,clang-analyzer-unix.*,bugprone-*,misc-*,performance-*,readability-*,-*,clang-analyzer-core.*,clang-analyzer-optin.performance.*,clang-analyzer-optin.portability.*,clang-analyzer-nullability.*,clang-analyzer-security.*,clang-analyzer-unix.*,bugprone-*,misc-*,performance-*,readability-*,-readability-isolate-declaration,-readability-else-after-return,-readability-braces-around-statements'
Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-core.*,clang-analyzer-optin.performance.*,clang-analyzer-optin.portability.*,clang-analyzer-nullability.*,clang-analyzer-security.*,clang-analyzer-unix.*,bugprone-*,misc-*,performance-*,readability-*,-*,clang-analyzer-core.*,clang-analyzer-optin.performance.*,clang-analyzer-optin.portability.*,clang-analyzer-nullability.*,clang-analyzer-security.*,clang-analyzer-unix.*,bugprone-*,misc-*,performance-*,readability-*,-readability-isolate-declaration,-readability-else-after-return,-readability-braces-around-statements,-*,clang-analyzer-core.*,clang-analyzer-optin.performance.*,clang-analyzer-optin.portability.*,clang-analyzer-nullability.*,clang-analyzer-security.*,clang-analyzer-unix.*,bugprone-*,misc-*,performance-*,readability-*,-readability-isolate-declaration,-readability-else-after-return,-readability-braces-around-statements,-readability-magic-numbers'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
FormatStyle: file
User: caskd
CheckOptions:
- key: bugprone-argument-comment.CommentBoolLiterals
@ -158,10 +158,6 @@ CheckOptions:
value: '1'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: '0'
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: '1.0;100.0;'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;'
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: '0'
- key: readability-redundant-smartptr-get.IgnoreMacros

View File

@ -1,19 +1,26 @@
cmake_minimum_required(VERSION 3.16)
project(microirc LANGUAGES C)
# NOTE: Do these seem too annoying? Try writing good code then.
# Code that triggers these warnings will not be accepted unless it has a good reason to trigger them.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Werror -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -pedantic -fanalyzer -fstack-check)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Weverything -Wno-padded -Wno-disabled-macro-expansion -pedantic)
endif()
OPTION(CMAKE_BUILD_TYPE "Debug")
OPTION(BUILD_TESTS "Build tests for ctest" OFF)
OPTION(BUILD_IRCV3 "Build IRCv3 components" ON)
OPTION(BUILD_HELPERS "Build message helpers" ON)
OPTION(BUILD_VALIDATORS "Build message validators" ON)
OPTION(CODE_ANALYZER "Analyze the code statically" ON)
OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
# NOTE: Do these seem too annoying? Try writing good code then.
# Code that triggers these warnings will not be accepted unless it has a good reason to trigger them.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Werror -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -pedantic -fstack-check)
if ( CODE_ANALYZER )
add_compile_options(-fanalyzer)
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Weverything -Wno-padded -Wno-disabled-macro-expansion -pedantic)
if ( CODE_COVERAGE )
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
endif()
endif()
if ( BUILD_IRCV3 )
message(STATUS "IRCv3 capabilities are going to be built.")

View File

@ -15,25 +15,27 @@
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
#include "types.h"
#include <stdbool.h>
#include <sys/types.h>
#ifndef UIRC_INCLUDED_FUNCT
#define UIRC_INCLUDED_FUNCT
#ifndef UIRC_GUARD_FUNCTIONS
#define UIRC_GUARD_FUNCTIONS
/* Tokenizers: They take a string in and point their struct element pointers at tokens and end tokens with '\0' */
extern signed int Tok_mesg(char* str, IRC_Message* out);
extern signed int Tok_user(char* str, IRC_User* out, bool useorig);
#ifdef UIRC_IRCV3
extern signed int Tok_tags(char* str, IRC_Tags* out);
#endif
#endif /* UIRC_IRCV3 */
/* Assemblers: They return the amount of bytes written and write directly at buf */
extern signed long Assm_mesg(char* buf, IRC_Message* in, size_t len);
extern signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig);
#ifdef UIRC_IRCV3
extern signed long Assm_tags(char* buf, IRC_Tags* in, size_t len);
#endif
#endif /* UIRC_IRCV3 */
/* Validators: They check that the parsed message is valid and follows the standard */
#ifdef UIRC_VALIDATORS
@ -42,9 +44,9 @@ extern signed int Val_channame(char* chan);
extern signed int Val_type_nocrlf(char* str);
extern signed int Val_type_nospcl(char* str);
extern signed int Val_type_noblcm(char* str);
#endif
#endif /* UIRC_VALIDATORS */
/* Converters: They convert from one format to another */
extern signed int Ircmd_stoi(char* str);
#endif
#endif /* UIRC_GUARD_FUNCTIONS */

View File

@ -15,13 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
#include "types.h"
#include <stdbool.h>
#include <time.h>
#ifdef UIRC_HELPERS
#ifndef UIRC_INCLUDED_HELPERS
#define UIRC_INCLUDED_HELPERS
#ifndef UIRC_GUARD_HELPERS
#define UIRC_GUARD_HELPERS
extern IRC_Message* Assm_AUTO(int cmd, bool trailing, char** args, int req);
@ -96,9 +99,10 @@ extern int Tok_CAPS(char* caps);
#define Assm_cmd_CAP_NEW(nick, caps) Assm_AUTO(CAP, true, (char*[]) { "NEW", nick, caps, NULL }, 2)
#define Assm_cmd_CAP_DEL(nick, caps) Assm_AUTO(CAP, true, (char*[]) { "DEL", nick, caps, NULL }, 2)
#endif
#endif /* UIRC_IRCV3 */
extern size_t Assm_tag_timestamp(char* buf, size_t len, time_t time);
#endif
#endif
#endif /* UIRC_GUARD_HELPERS */
#endif /* UIRC_HELPERS */

View File

@ -16,8 +16,8 @@
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef UIRC_INCLUDED_MAPS
#define UIRC_INCLUDED_MAPS
#ifndef UIRC_GUARD_MAPS
#define UIRC_GUARD_MAPS
#define ERR_UIRC_GENERIC -1
#define ERR_UIRC_NULL_ARGS -2
@ -53,7 +53,7 @@
#define CAP_TLS 19
#define CAP_USERHOST_IN_NAMES 20
#define CAPBIT(cap) (1 << cap)
#endif
#endif /* UIRC_IRCV3 */
#define UIRC_FCMD ADMIN
enum commands {
@ -121,10 +121,10 @@ enum commands {
WEBIRC, /* https://ircv3.net/specs/extensions/webirc */
#define UIRC_LCMD WEBIRC
#else
#else /* UIRC_IRCV3 */
#define UIRC_LCMD WHOWAS
#endif
#endif /* UIRC_IRCV3 */
};
#define RPL_WELCOME 1
#define RPL_YOURHOST 2
@ -141,7 +141,7 @@ enum commands {
* Read the above and go speak with them, or just don't use IRCv3 :)
*/
#define RPL_ISUPPORT 5
#endif
#endif /* UIRC_IRCV3 */
#define RPL_TRACELINK 200
#define RPL_TRACECONNECTING 201
@ -283,12 +283,12 @@ enum commands {
#define ERR_SASLABORTED 906
#define ERR_SASLALREADY 907
#define ERR_SASLMECHS 908
#endif
#endif
#endif /* UIRC_IRCV3 */
extern const char* const IRC_Cmds[UIRC_LCMD + UIRC_FCMD];
#ifdef UIRC_IRCV3
extern const char* const IRC_v3_Caps[CAP_USERHOST_IN_NAMES + 1];
#endif
#endif /* UIRC_IRCV3 */
#endif /* UIRC_GUARD_MAPS */

View File

@ -17,8 +17,8 @@
*/
#include <stdbool.h>
#ifndef UIRC_INCLUDED_TYPES
#define UIRC_INCLUDED_TYPES
#ifndef UIRC_GUARD_TYPES
#define UIRC_GUARD_TYPES
#ifdef UIRC_IRCV3
typedef struct {
@ -28,24 +28,12 @@ typedef struct {
typedef struct {
/* See https://ircv3.net/registry#tags for more information */
IRC_Tag account;
IRC_Tag batch;
IRC_Tag label;
IRC_Tag msgid;
IRC_Tag multiline_concat;
IRC_Tag time;
IRC_Tag typing;
IRC_Tag react;
IRC_Tag reply;
IRC_Tag account, batch, label, msgid, multiline_concat, time, typing, react, reply;
} IRC_Tags;
#endif
#endif /* UIRC_IRCV3 */
typedef struct {
char* nick;
char* user;
char* host;
char* orig;
char* real;
char* nick, *user, *host, *orig, *real;
} IRC_User;
/* This is how a full user source would look like
* NOTE: 'real (Real name)' may only be used in special contexts other than communication.
@ -56,11 +44,12 @@ typedef unsigned short IRC_Command;
typedef struct {
#ifdef UIRC_IRCV3
IRC_Tags tags;
#endif
#endif /* UIRC_IRCV3 */
IRC_User name;
char* args[16]; /* 0-13 + trailing + NULL */
bool trailing; /* Tells if the last argument is trailing */
IRC_Command cmd;
} IRC_Message;
#endif
#endif /* UIRC_GUARD_TYPES */

View File

@ -20,9 +20,11 @@
#include "helpers.h"
#include "mappings.h"
#include "types.h"
#ifndef UIRC_INCLUDED
#define UIRC_INCLUDED
#define UIRC_VERSION 20203110
#endif
#ifndef UIRC_GUARD_UIRC
#define UIRC_GUARD_UIRC
#define UIRC_VERSION 20201216
#endif /* UIRC_GUARD_UIRC */

View File

@ -17,37 +17,34 @@
*/
#include "assemblers.h"
signed long Assm_mesg(char* buf, IRC_Message* in, size_t len)
signed long
Assm_mesg(char* buf, IRC_Message* in, size_t len)
{
if (buf == NULL || in == NULL) return ERR_UIRC_BUFFER_ERR;
char* pos = buf;
signed long cnt, ret;
#ifdef UIRC_IRCV3
if ((ret = Assm_tags(pos, &in->tags, len - (unsigned long)(pos - buf))) < 0)
return ret;
if ((ret = Assm_tags(pos, &in->tags, len - (unsigned long) (pos - buf))) < 0) return ret;
else if (ret != 0) {
pos += ret;
if (!safe_charcpy(&pos, ' ', len - (unsigned long) (pos - buf))) return ERR_UIRC_BUFFER_ERR;
}
#endif
#endif /* UIRC_IRCV3 */
if (in->name.nick != NULL || in->name.host != NULL) {
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;
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 (in->cmd < UIRC_FCMD || in->cmd > UIRC_LCMD) {
if ((cnt = snprintf(pos, 4, "%.3i", in->cmd)) == 3)
pos += cnt;
if ((cnt = snprintf(pos, 4, "%.3i", in->cmd)) == 3) pos += cnt;
else
return ERR_UIRC_UNKNOWN_TOKEN;
} else {
if (IRC_Cmds[in->cmd] != NULL) {
size_t cmdlen = strlen(IRC_Cmds[in->cmd]);
if (len - (unsigned long)(pos - buf) > cmdlen && strcpy(pos, IRC_Cmds[in->cmd]) != NULL)
pos += cmdlen;
if (len - (unsigned long) (pos - buf) > cmdlen && strcpy(pos, IRC_Cmds[in->cmd]) != NULL) pos += cmdlen;
else
return ERR_UIRC_UNKNOWN_TOKEN;
}
@ -66,7 +63,8 @@ signed long Assm_mesg(char* buf, IRC_Message* in, size_t len)
}
#ifdef UIRC_IRCV3
signed long Assm_tags(char* buf, IRC_Tags* in, size_t len)
signed long
Assm_tags(char* buf, IRC_Tags* in, size_t len)
{
if (buf == NULL || in == NULL) return ERR_UIRC_NULL_ARGS;
char* pos = buf;
@ -94,9 +92,10 @@ signed long Assm_tags(char* buf, IRC_Tags* in, size_t len)
}
return pos - buf;
}
#endif
#endif /* UIRC_IRCV3*/
signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig)
signed long
Assm_user(char* buf, IRC_User* in, size_t len, bool useorig)
{
if (buf == NULL || in == NULL) return ERR_UIRC_NULL_ARGS;
char* pos = buf;

View File

@ -19,18 +19,19 @@
#include "../include/mappings.h"
#include "../include/types.h"
#include "misc.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifndef UIRC_INCLUDED_PRIVATE_ASSM
#define UIRC_INCLUDED_PRIVATE_ASSM
#ifndef UIRC_GUARD_PRIVATE_ASSEMBLERS
#define UIRC_GUARD_PRIVATE_ASSEMBLERS
signed long Assm_mesg(char* buf, IRC_Message* in, size_t len);
#ifdef UIRC_IRCV3
signed long Assm_tags(char* buf, IRC_Tags* in, size_t len);
#endif
#endif /* UIRC_IRCV3 */
signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig);
#endif
#endif /* UIRC_GUARD_PRIVATE_ASSEMBLERS */

View File

@ -20,8 +20,13 @@
static IRC_Message imassm_mesg;
char* RESERVED = "*";
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)
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;
@ -32,7 +37,8 @@ IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes)
IRC_Message*
Assm_cmd_USER(char* user, char* realname, int modes)
{
if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS)) return NULL;
clear_assm();
@ -47,7 +53,8 @@ IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask)
IRC_Message*
Assm_cmd_LINKS(char* remoteserv, char* servmask)
{
if (remoteserv != NULL && servmask == NULL) return NULL;
clear_assm();
@ -57,7 +64,8 @@ IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_WHO(char* mask, bool oper)
IRC_Message*
Assm_cmd_WHO(char* mask, bool oper)
{
static char* operator= "o";
if (oper && mask == NULL) return NULL;
@ -68,7 +76,8 @@ IRC_Message* Assm_cmd_WHO(char* mask, bool oper)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_WHOIS(char* target, char* mask)
IRC_Message*
Assm_cmd_WHOIS(char* target, char* mask)
{
if (mask == NULL) return NULL;
clear_assm();
@ -78,7 +87,8 @@ IRC_Message* Assm_cmd_WHOIS(char* target, char* mask)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target)
IRC_Message*
Assm_cmd_WHOWAS(char* nick, char* count, char* target)
{
if (nick == NULL || (target != NULL && count == NULL)) return NULL;
clear_assm();
@ -92,7 +102,8 @@ IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target)
/* NOTE: This is what implementation you have to live with
* I would've just used the prefix to set the source but whatever
*/
IRC_Message* Assm_cmd_PING(char* source, char* target)
IRC_Message*
Assm_cmd_PING(char* source, char* target)
{
if (source == NULL && target == NULL) return NULL;
clear_assm();
@ -103,7 +114,8 @@ IRC_Message* Assm_cmd_PING(char* source, char* target)
return &imassm_mesg;
}
IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel)
IRC_Message*
Assm_cmd_SUMMON(char* user, char* target, char* channel)
{
if (user == NULL || (channel != NULL && target == NULL)) return NULL;
clear_assm();
@ -113,7 +125,8 @@ IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel)
imassm_mesg.cmd = SUMMON;
return &imassm_mesg;
}
IRC_Message* Assm_cmd_USERHOST(char* users[])
IRC_Message*
Assm_cmd_USERHOST(char* users[])
{
if (users[0] == NULL) return NULL;
clear_assm();
@ -122,7 +135,8 @@ IRC_Message* Assm_cmd_USERHOST(char* users[])
return &imassm_mesg;
}
/* NOTE: Limited to 14 nicks per command */
IRC_Message* Assm_cmd_ISON(char* users[])
IRC_Message*
Assm_cmd_ISON(char* users[])
{
if (users[0] == NULL) return NULL;
clear_assm();
@ -131,7 +145,8 @@ IRC_Message* Assm_cmd_ISON(char* users[])
return &imassm_mesg;
}
void Tok_cmd_PING(IRC_Message* mesg, char** source, char** target)
void
Tok_cmd_PING(IRC_Message* mesg, char** source, char** target)
{
*source = (mesg->args[0] == NULL && mesg->trailing) ? mesg->args[2] : (mesg->args[1] != NULL) ? mesg->args[0] : NULL;
*target = (mesg->args[1] == NULL) ? mesg->args[0] : mesg->args[1];
@ -140,13 +155,15 @@ void Tok_cmd_PING(IRC_Message* mesg, char** source, char** target)
* (stands for first argument optional)
* [ <optarg> ] <reqarg>
*/
void Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg)
void
Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg)
{
*optarg = (mesg->args[1] != NULL) ? mesg->args[0] : NULL;
*reqarg = (mesg->args[1] != NULL) ? mesg->args[1] : mesg->args[0];
}
int Tok_CAPS(char* caps)
int
Tok_CAPS(char* caps)
{
int temp = 0;
char* cur = NULL;

View File

@ -18,14 +18,15 @@
#include "../include/mappings.h"
#include "../include/types.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifndef UIRC_INCLUDED_PRIVATE_HELPERS
#define UIRC_INCLUDED_PRIVATE_HELPERS
#ifndef UIRC_GUARD_PRIVATE_HELPERS
#define UIRC_GUARD_PRIVATE_HELPERS
extern char* RESERVED;
void clear_assm(void);
@ -44,5 +45,5 @@ IRC_Message* Assm_cmd_ISON(char* users[]);
void Tok_cmd_PING(IRC_Message* mesg, char** source, char** target);
void Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg);
int Tok_CAPS(char* caps);
#endif
#endif /* UIRC_GUARD_PRIVATE_HELPERS */

View File

@ -34,7 +34,7 @@ const char* const IRC_Cmds[] = {[ADMIN] = "ADMIN", [AWAY] = "AWAY", [C
[BATCH] = "BATCH", [CAP] = "CAP", [CHGHOST] = "CHGHOST", [FAIL] = "FAIL",
[MONITOR] = "MONITOR", [NOTE] = "NOTE", [RENAME] = "RENAME", [RESUME] = "RESUME",
[SETNAME] = "SETNAME", [WARN] = "WARN", [WEBIRC] = "WEBIRC"
#endif
#endif /* UIRC_IRCV3 */
};
#ifdef UIRC_IRCV3
@ -60,9 +60,10 @@ const char* const IRC_v3_Caps[] = {
[CAP_TLS] = "tls",
[CAP_USERHOST_IN_NAMES] = "userhost-in-names",
};
#endif
#endif /* UIRC_IRCV3 */
signed short Ircmd_stoi(char* str)
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++) {
@ -71,7 +72,8 @@ signed short Ircmd_stoi(char* str)
return ERR_UIRC_UNKNOWN_TOKEN;
}
size_t safe_strcpy(char** dest, const char* src, size_t lef)
size_t
safe_strcpy(char** dest, const char* src, size_t lef)
{
size_t cnt;
if (lef > (cnt = strlen(src)) + 1) {
@ -82,7 +84,8 @@ size_t safe_strcpy(char** dest, const char* src, size_t lef)
return 0;
}
bool safe_charcpy(char** dest, const char c, size_t lef)
bool
safe_charcpy(char** dest, const char c, size_t lef)
{
if (lef > 1) {
*(*dest)++ = c;
@ -92,13 +95,15 @@ bool safe_charcpy(char** dest, const char c, size_t lef)
return 0;
}
void skip_spaces(char** addr)
void
skip_spaces(char** addr)
{
for (; **addr == ' '; (*addr)++)
;
}
char* strtok_mr(char** addr, const char* tokens)
char*
strtok_mr(char** addr, const char* tokens)
{
if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) return NULL;
char* save = *addr;

View File

@ -18,23 +18,24 @@
#include "../include/mappings.h"
#include "../include/types.h"
#include <stdio.h>
#include <string.h>
#ifndef UIRC_INCLUDED_PRIVATE_MISC
#define UIRC_INCLUDED_PRIVATE_MISC
#ifndef UIRC_GUARD_PRIVATE_MISC
#define UIRC_GUARD_PRIVATE_MISC
#ifdef UIRC_IRCV3
struct tagmapping {
const char* const name;
IRC_Tag* assg;
};
#endif
#endif /* UIRC_IRCV3 */
signed short Ircmd_stoi(char* str);
size_t safe_strcpy(char** dest, const char* src, size_t lef);
bool safe_charcpy(char** dest, char c, size_t lef);
void skip_spaces(char** addr);
char* strtok_mr(char** addr, const char* tokens);
#endif
#endif /* UIRC_GUARD_PRIVATE_MISC */

View File

@ -22,8 +22,8 @@
#include <time.h>
#include <unistd.h>
#ifndef UIRC_INCLUDED_PRIVATE_TAGHELPERS
#define UIRC_INCLUDED_PRIVATE_TAGHELPERS
#ifndef UIRC_GUARD_PRIVATE_TAGHELPERS
#define UIRC_GUARD_PRIVATE_TAGHELPERS
size_t Assm_tag_timestamp(char* buf, size_t len, time_t time);
#endif
#endif /* UIRC_GUARD_PRIVATE_TAGHELPERS */

View File

@ -17,7 +17,8 @@
*/
#include "tokenizers.h"
signed int Tok_mesg(char* str, IRC_Message* out)
signed int
Tok_mesg(char* str, IRC_Message* out)
{
if (str == NULL || out == NULL) return ERR_UIRC_NULL_ARGS;
int ret;
@ -31,7 +32,7 @@ signed int Tok_mesg(char* str, IRC_Message* out)
return ERR_UIRC_INVALID_FORMAT;
}
skip_spaces(&progr);
#endif
#endif /* UIRC_IRCV3 */
if (*progr == ':') {
char* prefix;
if ((prefix = strtok_mr(&progr, " ")) != NULL) {
@ -71,16 +72,19 @@ signed int Tok_mesg(char* str, IRC_Message* out)
}
#ifdef UIRC_IRCV3
signed int Tok_tags(char* str, IRC_Tags* out)
signed int
Tok_tags(char* str, IRC_Tags* out)
{
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},
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}};
{ .name = "reply", .assg = &out->reply }
};
if (*cpos == '@') cpos++;
while ((ctag = strtok_mr(&cpos, "; ")) != NULL) {
clientbound = false;
@ -102,9 +106,10 @@ signed int Tok_tags(char* str, IRC_Tags* out)
}
return 1;
}
#endif
#endif /* UIRC_IRCV3 */
signed int Tok_user(char* str, IRC_User* out, bool useorig)
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';

View File

@ -19,19 +19,20 @@
#include "../include/mappings.h"
#include "../include/types.h"
#include "misc.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef UIRC_INCLUDED_PRIVATE_TKNIZ
#define UIRC_INCLUDED_PRIVATE_TKNIZ
#ifndef UIRC_GUARD_PRIVATE_TOKENIZERS
#define UIRC_GUARD_PRIVATE_TOKENIZERS
signed int Tok_mesg(char* str, IRC_Message* out);
#ifdef UIRC_IRCV3
signed int Tok_tags(char* str, IRC_Tags* out);
#endif
#endif /* UIRC_IRCV3 */
signed int Tok_user(char* str, IRC_User* out, bool useorig);
#endif
#endif /* UIRC_GUARD_PRIVATE_TOKENIZERS */

View File

@ -1,4 +1,3 @@
/*
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
* Copyright (c) 2019, 2020 Alex-David Denes
@ -18,7 +17,8 @@
*/
#include "validators.h"
signed int Val_mesg(IRC_Message* mesg)
signed int
Val_mesg(IRC_Message* mesg)
{
if (mesg == NULL) return ERR_UIRC_NULL_ARGS;
for (unsigned int i = 0; mesg->args[i] != NULL; i++) {
@ -30,7 +30,8 @@ signed int Val_mesg(IRC_Message* mesg)
return 1;
}
signed int Val_type_nocrlf(char* str)
signed int
Val_type_nocrlf(char* str)
{
if (str == NULL) return ERR_UIRC_NULL_ARGS;
for (; *str; str++) {
@ -39,7 +40,8 @@ signed int Val_type_nocrlf(char* str)
return 1;
}
signed int Val_type_nospcl(char* str)
signed int
Val_type_nospcl(char* str)
{
if (str == NULL) return ERR_UIRC_NULL_ARGS;
for (; *str; str++) {
@ -48,7 +50,8 @@ signed int Val_type_nospcl(char* str)
return 1;
}
signed int Val_type_noblcm(char* str)
signed int
Val_type_noblcm(char* str)
{
if (str == NULL) return ERR_UIRC_NULL_ARGS;
for (; *str; str++) {
@ -57,7 +60,8 @@ signed int Val_type_noblcm(char* str)
return 1;
}
signed int Val_channame(char* chan)
signed int
Val_channame(char* chan)
{
if (chan == NULL) return ERR_UIRC_NULL_ARGS;
if (*chan != '#' && *chan != '+' && *chan != '!' && *chan != '&') return 0;

View File

@ -18,15 +18,16 @@
#include "../include/mappings.h"
#include "../include/types.h"
#include <stdio.h>
#include <string.h>
#ifndef UIRC_INCLUDED_PRIVATE_VALIDATORS
#define UIRC_INCLUDED_PRIVATE_VALIDATORS
#ifndef UIRC_GUARD_PRIVATE_VALIDATORS
#define UIRC_GUARD_PRIVATE_VALIDATORS
signed int Val_mesg(IRC_Message* mesg);
signed int Val_type_nocrlf(char* str);
signed int Val_type_nospcl(char* str);
signed int Val_type_noblcm(char* str);
signed int Val_channame(char* chan);
#endif
#endif /* UIRC_GUARD_PRIVATE_VALIDATORS */