Reformat code according to new style

This commit is contained in:
Alex D. 2020-10-10 12:30:05 +02:00
parent 0a76421f0a
commit a60d0039c1
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
27 changed files with 152 additions and 282 deletions

View File

@ -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
...

View File

@ -14,7 +14,7 @@
*
* 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>

View File

@ -14,7 +14,7 @@
*
* 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>
@ -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);

View File

@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#ifndef UIRC_INCLUDED_ENUMS
#define UIRC_INCLUDED_ENUMS

View File

@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include <stdbool.h>
#ifndef UIRC_INCLUDED_TYPES

View File

@ -14,12 +14,12 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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

View File

@ -14,13 +14,12 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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;

View File

@ -14,10 +14,10 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include "../include/types.h"
#include "../include/mappings.h"
#include "../include/types.h"
#include "misc.h"
#include <stdio.h>
#include <string.h>

View File

@ -14,25 +14,19 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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;
}

View File

@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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);

View File

@ -14,82 +14,34 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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';

View File

@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include "../include/mappings.h"
#include "../include/types.h"

View File

@ -14,12 +14,9 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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)); }

View File

@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include <stdio.h>
#include <stdlib.h>

View File

@ -14,21 +14,19 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#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

View File

@ -14,15 +14,15 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include "../include/types.h"
#include "../include/mappings.h"
#include "../include/types.h"
#include "misc.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef UIRC_INCLUDED_TKNIZ
#define UIRC_INCLUDED_TKNIZ

View File

@ -15,19 +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 "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;
}

View File

@ -14,10 +14,10 @@
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
*/
#include "../include/types.h"
#include "../include/mappings.h"
#include "../include/types.h"
#include <stdio.h>
#include <string.h>

View File

@ -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,

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {