Code refactoring
- Merged public and private headers - Moved private includes to sources and only kept public includes in headers - Split files - Replaced defines with enums - Changed include paths for tests and moved cmake build defs from there - Added headers to tests
This commit is contained in:
parent
a047a9c6d8
commit
7e2a0b24c7
|
@ -15,16 +15,23 @@ OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
|
|||
|
||||
set(UIRC_SOURCE
|
||||
src/assemblers.c
|
||||
src/misc.c
|
||||
src/commands.c
|
||||
src/converters.c
|
||||
src/memory.c
|
||||
src/string.c
|
||||
src/tokenizers.c
|
||||
)
|
||||
|
||||
set(UIRC_HEADERS
|
||||
include/functions.h
|
||||
include/helpers.h
|
||||
include/mappings.h
|
||||
include/types.h
|
||||
include/uirc.h
|
||||
src/assemblers.h
|
||||
src/commands.h
|
||||
src/converters.h
|
||||
src/errors.h
|
||||
src/modes.h
|
||||
src/replies.h
|
||||
src/tokenizers.h
|
||||
src/types.h
|
||||
src/uirc.h
|
||||
)
|
||||
|
||||
#
|
||||
|
@ -33,24 +40,57 @@ set(UIRC_HEADERS
|
|||
if (BUILD_IRCV3)
|
||||
message(STATUS "IRCv3 capabilities are going to be built.")
|
||||
add_compile_definitions(UIRC_IRCV3)
|
||||
set(UIRC_SOURCE ${UIRC_SOURCE}
|
||||
src/tags.c
|
||||
src/capabilities.c
|
||||
)
|
||||
set(UIRC_HEADERS ${UIRC_HEADERS}
|
||||
src/tags.h
|
||||
src/capabilities.h
|
||||
)
|
||||
endif()
|
||||
if (BUILD_VALIDATORS)
|
||||
message(STATUS "Message validators are going to be built.")
|
||||
add_compile_definitions(UIRC_VALIDATORS)
|
||||
set(UIRC_SOURCE ${UIRC_SOURCE} src/validators.c)
|
||||
set(UIRC_SOURCE ${UIRC_SOURCE}
|
||||
src/validators.c
|
||||
)
|
||||
set(UIRC_HEADERS ${UIRC_HEADERS}
|
||||
src/validators.h
|
||||
)
|
||||
endif()
|
||||
if (BUILD_HELPERS)
|
||||
message(STATUS "Helper functions are going to be built.")
|
||||
set(UIRC_SOURCE ${UIRC_SOURCE} src/helpers.c)
|
||||
add_compile_definitions(UIRC_HELPERS)
|
||||
if (BUILD_IRCV3)
|
||||
set(UIRC_SOURCE ${UIRC_SOURCE} src/taghelpers.c)
|
||||
endif()
|
||||
endif()
|
||||
if (BUILD_TESTS)
|
||||
message(STATUS "Tests are going to be built.")
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
|
||||
macro(buildtest name source)
|
||||
add_executable(${source} tests/${source}.c)
|
||||
target_link_libraries(${source} uirc)
|
||||
add_test(NAME ${name} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${source})
|
||||
endmacro()
|
||||
|
||||
buildtest(Tokenizer tokenizer)
|
||||
buildtest(Overflow overflow)
|
||||
buildtest(PrefixAssembler prefixassm)
|
||||
buildtest(MessageAssembler msgassm)
|
||||
buildtest(NumericCmds numericmds)
|
||||
buildtest(IncorrectTrailing notrail)
|
||||
buildtest(SpacedArguments spacedargs)
|
||||
buildtest(StrTokMoveSave strtokmr)
|
||||
buildtest(Junk junk)
|
||||
|
||||
if (BUILD_IRCV3)
|
||||
buildtest(TagParser tagtok)
|
||||
buildtest(TagAssembler tagassm)
|
||||
if (BUILD_HELPERS)
|
||||
buildtest(TimestampAssembly timestamp)
|
||||
buildtest(TagBitMaskTknzr capbitmask)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(uirc ${UIRC_SOURCE})
|
||||
|
@ -101,5 +141,5 @@ set_target_properties(uirc PROPERTIES
|
|||
install(
|
||||
TARGETS uirc
|
||||
LIBRARY
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uirc
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/uirc"
|
||||
)
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#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 /* 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 /* UIRC_IRCV3 */
|
||||
|
||||
/* Validators: They check that the parsed message is valid and follows the standard */
|
||||
#ifdef UIRC_VALIDATORS
|
||||
extern signed int Val_mesg(IRC_Message* mesg);
|
||||
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 /* UIRC_VALIDATORS */
|
||||
|
||||
/* Converters: They convert from one format to another */
|
||||
extern signed int Ircmd_stoi(char* str);
|
||||
#endif /* UIRC_GUARD_FUNCTIONS */
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
|
||||
#ifndef UIRC_GUARD_HELPERS
|
||||
#define UIRC_GUARD_HELPERS
|
||||
|
||||
extern IRC_Message* Assm_AUTO(int cmd, bool trailing, char** args, int req);
|
||||
|
||||
#define Assm_cmd_REHASH() Assm_AUTO(REHASH, false, (char*[]) { NULL }, 0)
|
||||
#define Assm_cmd_DIE() Assm_AUTO(DIE, false, (char*[]) { NULL }, 0)
|
||||
#define Assm_cmd_RESTART() Assm_AUTO(RESTART, false, (char*[]) { NULL }, 0)
|
||||
|
||||
#define Assm_cmd_QUIT(message) Assm_AUTO(QUIT, true, (char*[]) { message, NULL }, 0)
|
||||
#define Assm_cmd_MOTD(target) Assm_AUTO(MOTD, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_VERSION(target) Assm_AUTO(VERSION, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_TIME(target) Assm_AUTO(TIME, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_TRACE(target) Assm_AUTO(TRACE, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_ADMIN(target) Assm_AUTO(ADMIN, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_INFO(target) Assm_AUTO(INFO, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_AWAY(message) Assm_AUTO(AWAY, false, (char*[]) { message, NULL }, 0)
|
||||
|
||||
#define Assm_cmd_PASS(password) Assm_AUTO(PASS, true, (char*[]) { password, NULL }, 1)
|
||||
#define Assm_cmd_ERROR(message) Assm_AUTO(ERROR, true, (char*[]) { message, NULL }, 1)
|
||||
#define Assm_cmd_WALLOPS(text) Assm_AUTO(WALLOPS, true, (char*[]) { text, NULL }, 1)
|
||||
#define Assm_cmd_NICK(nickname) Assm_AUTO(NICK, false, (char*[]) { nickname, NULL }, 1)
|
||||
#define Assm_cmd_USERS(target) Assm_AUTO(USERS, false, (char*[]) { target, NULL }, 1)
|
||||
|
||||
#define Assm_cmd_NAMES(channels, target) Assm_AUTO(NAMES, false, (char*[]) { channels, target, NULL }, 0)
|
||||
#define Assm_cmd_LIST(channels, target) Assm_AUTO(LIST, false, (char*[]) { channels, target, NULL }, 0)
|
||||
#define Assm_cmd_LUSERS(mask, target) Assm_AUTO(LUSERS, false, (char*[]) { mask, target, NULL }, 0)
|
||||
#define Assm_cmd_STATS(query, target) Assm_AUTO(STATS, false, (char*[]) { query, target, NULL }, 0)
|
||||
#define Assm_cmd_SERVLIST(mask, type) Assm_AUTO(SERVLIST, false, (char*[]) { mask, type, NULL }, 0)
|
||||
|
||||
#define Assm_cmd_JOIN(channels, keys) Assm_AUTO(JOIN, false, (char*[]) { channels, keys, NULL }, 1)
|
||||
#define Assm_cmd_PART(channel, message) Assm_AUTO(PART, false, (char*[]) { channel, message, NULL }, 1)
|
||||
/* NOTE: Use a non-NULL address (pointing at a "\0") as the topic to clear it and use a NULL address to check it
|
||||
* Blame the protocol, not this >:C */
|
||||
#define Assm_cmd_TOPIC(channel, topic) Assm_AUTO(TOPIC, true, (char*[]) { channel, topic, NULL }, 1)
|
||||
#define Assm_cmd_PONG(source, target) Assm_AUTO(PONG, true, (char*[]) { source, target, NULL }, 1)
|
||||
|
||||
#define Assm_cmd_OPER(name, password) Assm_AUTO(OPER, true, (char*[]) { name, password, NULL }, 2)
|
||||
#define Assm_cmd_SQUIT(server, comment) Assm_AUTO(SQUIT, true, (char*[]) { server, comment, NULL }, 2)
|
||||
#define Assm_cmd_PRIVMSG(target, message) Assm_AUTO(PRIVMSG, true, (char*[]) { target, message, NULL }, 2)
|
||||
#define Assm_cmd_NOTICE(target, text) Assm_AUTO(NOTICE, true, (char*[]) { target, text, NULL }, 2)
|
||||
#define Assm_cmd_SQUERY(servicename, text) Assm_AUTO(SQUERY, true, (char*[]) { servicename, text, NULL }, 2)
|
||||
#define Assm_cmd_KILL(nick, comment) Assm_AUTO(KILL, true, (char*[]) { nick, comment, NULL }, 2)
|
||||
#define Assm_cmd_INVITE(nick, channel) Assm_AUTO(INVITE, false, (char*[]) { nick, channel, NULL }, 2)
|
||||
|
||||
#define Assm_cmd_MODE(nickname, modes, modeparams) Assm_AUTO(MODE, false, (char*[]) { nickname, modes, modeparams, NULL }, 1)
|
||||
|
||||
#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)
|
||||
|
||||
extern IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes);
|
||||
extern IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask);
|
||||
extern IRC_Message* Assm_cmd_WHO(char* mask, bool oper);
|
||||
extern IRC_Message* Assm_cmd_WHOIS(char* target, char* mask);
|
||||
extern IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target);
|
||||
extern IRC_Message* Assm_cmd_PING(char* source, char* target);
|
||||
extern IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel);
|
||||
extern IRC_Message* Assm_cmd_USERHOST(char* users[]);
|
||||
extern IRC_Message* Assm_cmd_ISON(char* users[]);
|
||||
|
||||
extern void Tok_cmd_PING(IRC_Message* mesg, char* source, char* target);
|
||||
extern void Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg);
|
||||
extern int Tok_CAPS(char* caps);
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
#define Assm_cmd_CAP_END() Assm_AUTO(CAP, false, (char*[]) { "END", NULL }, 0)
|
||||
#define Assm_cmd_CAP_LIST() Assm_AUTO(CAP, false, (char*[]) { "LIST", NULL }, 0)
|
||||
|
||||
#define Assm_cmd_CAP_LS(version) Assm_AUTO(CAP, false, (char*[]) { "LS", version, NULL }, 0)
|
||||
#define Assm_cmd_CAP_REQ(caps) Assm_AUTO(CAP, true, (char*[]) { "REQ", caps, NULL }, 1)
|
||||
|
||||
#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 /* UIRC_IRCV3 */
|
||||
|
||||
extern size_t Assm_tag_timestamp(char* buf, size_t len, time_t time);
|
||||
|
||||
#endif /* UIRC_GUARD_HELPERS */
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
|
@ -1,294 +0,0 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_MAPS
|
||||
#define UIRC_GUARD_MAPS
|
||||
|
||||
#define ERR_UIRC_GENERIC -1
|
||||
#define ERR_UIRC_NULL_ARGS -2
|
||||
#define ERR_UIRC_INVALID_FORMAT -3
|
||||
#define ERR_UIRC_BUFFER_ERR -4
|
||||
#define ERR_UIRC_UNKNOWN_TOKEN -5
|
||||
#define ERR_UIRC_VAL_FAILED -10
|
||||
|
||||
/* Mode bitmask values */
|
||||
#define MBMASK_WALLOPS 1 << 1 /* 010 */
|
||||
#define MBMASK_INVIS 1 << 2 /* 100 */
|
||||
|
||||
/* IRCv3 Supported features bits */
|
||||
#ifdef UIRC_IRCV3
|
||||
#define CAP_ACCOUNT_NOTIFY 1
|
||||
#define CAP_ACCOUNT_TAG 2
|
||||
#define CAP_AWAY_NOTIFY 3
|
||||
#define CAP_BATCH 4
|
||||
#define CAP_CAP_NOTIFY 5
|
||||
#define CAP_CHANNEL_RENAME 6
|
||||
#define CAP_CHGHOST 7
|
||||
#define CAP_ECHO_MESSAGE 8
|
||||
#define CAP_EXTENDED_JOIN 9
|
||||
#define CAP_INVITE_NOTIFY 10
|
||||
#define CAP_LABELED_RESPONSE 11
|
||||
#define CAP_MESSAGE_TAGS 12
|
||||
#define CAP_MONITOR 13
|
||||
#define CAP_MULTI_PREFIX 14
|
||||
#define CAP_MULTILINE 15
|
||||
#define CAP_SASL 16
|
||||
#define CAP_SERVER_TIME 17
|
||||
#define CAP_SETNAME 18
|
||||
#define CAP_TLS 19
|
||||
#define CAP_USERHOST_IN_NAMES 20
|
||||
#define CAPBIT(cap) (1 << cap)
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
#define UIRC_FCMD ADMIN
|
||||
enum commands {
|
||||
ADMIN = 10,
|
||||
AWAY,
|
||||
CONNECT,
|
||||
DIE,
|
||||
ERROR,
|
||||
INFO,
|
||||
INVITE,
|
||||
ISON,
|
||||
JOIN,
|
||||
KICK,
|
||||
KILL,
|
||||
LINKS,
|
||||
LIST,
|
||||
LUSERS,
|
||||
MODE,
|
||||
MOTD,
|
||||
NAMES,
|
||||
NICK,
|
||||
NOTICE,
|
||||
OPER,
|
||||
PART,
|
||||
PASS,
|
||||
PING,
|
||||
PONG,
|
||||
PRIVMSG,
|
||||
QUIT,
|
||||
REHASH,
|
||||
RESTART,
|
||||
SERVER,
|
||||
SERVICE,
|
||||
SERVLIST,
|
||||
SQUERY,
|
||||
SQUIT,
|
||||
STATS,
|
||||
SUMMON,
|
||||
TIME,
|
||||
TOPIC,
|
||||
TRACE,
|
||||
USER,
|
||||
USERHOST,
|
||||
USERS,
|
||||
VERSION,
|
||||
WALLOPS,
|
||||
WHO,
|
||||
WHOIS,
|
||||
WHOWAS,
|
||||
#ifdef UIRC_IRCV3
|
||||
ACC, /* https://github.com/ircv3/ircv3-specifications/pull/276 */
|
||||
ACCOUNT, /* https://ircv3.net/specs/extensions/account-notify-3.1 */
|
||||
ACK, /* https://ircv3.net/specs/extensions/labeled-response */
|
||||
AUTHENTICATE, /* https://ircv3.net/specs/extensions/sasl-3.1 */
|
||||
BATCH, /* https://ircv3.net/specs/extensions/batch-3.2 */
|
||||
CAP, /* https://ircv3.net/specs/core/capability-negotiation */
|
||||
CHGHOST, /* https://ircv3.net/specs/extensions/chghost-3.2 */
|
||||
FAIL, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
MONITOR, /* https://ircv3.net/specs/core/monitor-3.2 */
|
||||
NOTE, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
RENAME, /* https://github.com/ircv3/ircv3-specifications/pull/420 */
|
||||
RESUME, /* https://github.com/ircv3/ircv3-specifications/pull/306 */
|
||||
SETNAME, /* https://ircv3.net/specs/extensions/setname */
|
||||
WARN, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
WEBIRC, /* https://ircv3.net/specs/extensions/webirc */
|
||||
#define UIRC_LCMD WEBIRC
|
||||
|
||||
#else /* UIRC_IRCV3 */
|
||||
|
||||
#define UIRC_LCMD WHOWAS
|
||||
#endif /* UIRC_IRCV3 */
|
||||
};
|
||||
#define RPL_WELCOME 1
|
||||
#define RPL_YOURHOST 2
|
||||
#define RPL_CREATED 3
|
||||
#define RPL_MYINFO 4
|
||||
#define RPL_BOUNCE 5
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
/* TO IRCv3 WG:
|
||||
* please, stop complicating implementations
|
||||
* get people in the WG that actually care about the protocol and understand why and how standards are written
|
||||
*
|
||||
* TO LIBRARY USERS:
|
||||
* Read the above and go speak with them, or just don't use IRCv3 :)
|
||||
*/
|
||||
#define RPL_ISUPPORT 5
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
#define RPL_TRACELINK 200
|
||||
#define RPL_TRACECONNECTING 201
|
||||
#define RPL_TRACEHANDSHAKE 202
|
||||
#define RPL_TRACEUNKNOWN 203
|
||||
#define RPL_TRACEOPERATOR 204
|
||||
#define RPL_TRACEUSER 205
|
||||
#define RPL_TRACESERVER 206
|
||||
#define RPL_TRACENEWTYPE 208
|
||||
#define RPL_STATSLINKINFO 211
|
||||
#define RPL_STATSCOMMANDS 212
|
||||
#define RPL_STATSCLINE 213
|
||||
#define RPL_STATSNLINE 214
|
||||
#define RPL_STATSILINE 215
|
||||
#define RPL_STATSKLINE 216
|
||||
#define RPL_STATSYLINE 218
|
||||
#define RPL_ENDOFSTATS 219
|
||||
#define RPL_UMODEIS 221
|
||||
#define RPL_STATSLLINE 241
|
||||
#define RPL_STATSUPTIME 242
|
||||
#define RPL_STATSOLINE 243
|
||||
#define RPL_STATSHLINE 244
|
||||
#define RPL_LUSERCLIENT 251
|
||||
#define RPL_LUSEROP 252
|
||||
#define RPL_LUSERUNKNOWN 253
|
||||
#define RPL_LUSERCHANNELS 254
|
||||
#define RPL_LUSERME 255
|
||||
#define RPL_ADMINME 256
|
||||
#define RPL_ADMINLOC1 257
|
||||
#define RPL_ADMINLOC2 258
|
||||
#define RPL_ADMINEMAIL 259
|
||||
#define RPL_TRACELOG 261
|
||||
#define RPL_NONE 300
|
||||
#define RPL_AWAY 301
|
||||
#define RPL_USERHOST 302
|
||||
#define RPL_ISON 303
|
||||
#define RPL_UNAWAY 305
|
||||
#define RPL_NOWAWAY 306
|
||||
#define RPL_WHOISUSER 311
|
||||
#define RPL_WHOISSERVER 312
|
||||
#define RPL_WHOISOPERATOR 313
|
||||
#define RPL_WHOWASUSER 314
|
||||
#define RPL_ENDOFWHO 315
|
||||
#define RPL_WHOISIDLE 317
|
||||
#define RPL_ENDOFWHOIS 318
|
||||
#define RPL_WHOISCHANNELS 319
|
||||
#define RPL_LISTSTART 321
|
||||
#define RPL_LIST 322
|
||||
#define RPL_LISTEND 323
|
||||
#define RPL_CHANNELMODEIS 324
|
||||
#define RPL_NOTOPIC 331
|
||||
#define RPL_TOPIC 332
|
||||
#define RPL_INVITING 341
|
||||
#define RPL_SUMMONING 342
|
||||
#define RPL_VERSION 351
|
||||
#define RPL_WHOREPLY 352
|
||||
#define RPL_NAMREPLY 353
|
||||
#define RPL_LINKS 364
|
||||
#define RPL_ENDOFLINKS 365
|
||||
#define RPL_ENDOFNAMES 366
|
||||
#define RPL_BANLIST 367
|
||||
#define RPL_ENDOFBANLIST 368
|
||||
#define RPL_ENDOFWHOWAS 369
|
||||
#define RPL_INFO 371
|
||||
#define RPL_MOTD 372
|
||||
#define RPL_ENDOFINFO 374
|
||||
#define RPL_MOTDSTART 375
|
||||
#define RPL_ENDOFMOTD 376
|
||||
#define RPL_YOUREOPER 381
|
||||
#define RPL_REHASHING 382
|
||||
#define RPL_TIME 391
|
||||
#define RPL_USERSSTART 392
|
||||
#define RPL_USERS 393
|
||||
#define RPL_ENDOFUSERS 394
|
||||
#define RPL_NOUSERS 395
|
||||
|
||||
#define ERR_NOSUCHNICK 401
|
||||
#define ERR_NOSUCHSERVER 402
|
||||
#define ERR_NOSUCHCHANNEL 403
|
||||
#define ERR_CANNOTSENDTOCHAN 404
|
||||
#define ERR_TOOMANYCHANNELS 405
|
||||
#define ERR_WASNOSUCHNICK 406
|
||||
#define ERR_TOOMANYTARGETS 407
|
||||
#define ERR_NOORIGIN 409
|
||||
#define ERR_NORECIPIENT 411
|
||||
#define ERR_NOTEXTTOSEND 412
|
||||
#define ERR_NOTOPLEVEL 413
|
||||
#define ERR_WILDTOPLEVEL 414
|
||||
#define ERR_UNKNOWNCOMMAND 421
|
||||
#define ERR_NOMOTD 422
|
||||
#define ERR_NOADMININFO 423
|
||||
#define ERR_FILEERROR 424
|
||||
#define ERR_NONICKNAMEGIVEN 431
|
||||
#define ERR_ERRONEUSNICKNAME 432
|
||||
#define ERR_NICKNAMEINUSE 433
|
||||
#define ERR_NICKCOLLISION 436
|
||||
#define ERR_USERNOTINCHANNEL 441
|
||||
#define ERR_NOTONCHANNEL 442
|
||||
#define ERR_USERONCHANNEL 443
|
||||
#define ERR_NOLOGIN 444
|
||||
#define ERR_SUMMONDISABLED 445
|
||||
#define ERR_USERSDISABLED 446
|
||||
#define ERR_NOTREGISTERED 451
|
||||
#define ERR_NEEDMOREPARAMS 461
|
||||
#define ERR_ALREADYREGISTRED 462
|
||||
#define ERR_NOPERMFORHOST 463
|
||||
#define ERR_PASSWDMISMATCH 464
|
||||
#define ERR_YOUREBANNEDCREEP 465
|
||||
#define ERR_KEYSET 467
|
||||
#define ERR_CHANNELISFULL 471
|
||||
#define ERR_UNKNOWNMODE 472
|
||||
#define ERR_INVITEONLYCHAN 473
|
||||
#define ERR_BANNEDFROMCHAN 474
|
||||
#define ERR_BADCHANNELKEY 475
|
||||
#define ERR_NOPRIVILEGES 481
|
||||
#define ERR_CHANOPRIVSNEEDED 482
|
||||
#define ERR_CANTKILLSERVER 483
|
||||
#define ERR_NOOPERHOST 491
|
||||
#define ERR_UMODEUNKNOWNFLAG 501
|
||||
#define ERR_USERSDONTMATCH 502
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
/* https://ircv3.net/registry */
|
||||
#define RPL_STARTTLS 670
|
||||
#define ERR_STARTTLS 691
|
||||
|
||||
#define RPL_MONONLINE 730
|
||||
#define RPL_MONOFFLINE 731
|
||||
#define RPL_MONLIST 732
|
||||
#define RPL_ENDOFMONLIST 733
|
||||
#define ERR_MOLISTFULL 734
|
||||
|
||||
#define RPL_LOGGEDIN 900
|
||||
#define RPL_LOGGEDOUT 901
|
||||
#define ERR_NICKLOCKED 902
|
||||
#define RPL_SASLSUCCESS 903
|
||||
#define ERR_SASLFAIL 904
|
||||
#define ERR_SASLTOOLONG 905
|
||||
#define ERR_SASLABORTED 906
|
||||
#define ERR_SASLALREADY 907
|
||||
#define ERR_SASLMECHS 908
|
||||
#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 /* UIRC_IRCV3 */
|
||||
|
||||
#endif /* UIRC_GUARD_MAPS */
|
||||
|
255
src/assemblers.c
255
src/assemblers.c
|
@ -15,8 +15,79 @@
|
|||
* 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"
|
||||
|
||||
#include "commands.h"
|
||||
#include "errors.h"
|
||||
#include "memory.h"
|
||||
#include "modes.h"
|
||||
#include "tags.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
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;
|
||||
if (in->nick == NULL && in->host != NULL) {
|
||||
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 (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 (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 (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;
|
||||
}
|
||||
} else
|
||||
return ERR_UIRC_NULL_ARGS;
|
||||
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;
|
||||
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 } };
|
||||
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;
|
||||
} else {
|
||||
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_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pos - buf;
|
||||
}
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
signed long
|
||||
Assm_mesg(char* buf, IRC_Message* in, size_t len)
|
||||
{
|
||||
|
@ -62,61 +133,137 @@ Assm_mesg(char* buf, IRC_Message* in, size_t len)
|
|||
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;
|
||||
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 } };
|
||||
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;
|
||||
} else {
|
||||
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_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pos - buf;
|
||||
}
|
||||
#endif /* UIRC_IRCV3*/
|
||||
#ifdef UIRC_HELPERS
|
||||
|
||||
signed long
|
||||
Assm_user(char* buf, IRC_User* in, size_t len, bool useorig)
|
||||
static IRC_Message imassm_mesg;
|
||||
#define RESERVED "*";
|
||||
|
||||
void
|
||||
clear_assm(void)
|
||||
{
|
||||
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;
|
||||
} else if (in->nick != NULL) {
|
||||
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 (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 (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;
|
||||
}
|
||||
} else
|
||||
return ERR_UIRC_NULL_ARGS;
|
||||
return pos - buf;
|
||||
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;
|
||||
imassm_mesg.trailing = trailing;
|
||||
imassm_mesg.cmd = cmd;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
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();
|
||||
static char local_mode[2];
|
||||
snprintf(local_mode, 2, "%i", modes);
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = local_mode;
|
||||
imassm_mesg.args[2] = RESERVED;
|
||||
imassm_mesg.args[3] = realname;
|
||||
imassm_mesg.trailing = true;
|
||||
imassm_mesg.cmd = USER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_LINKS(char* remoteserv, char* servmask)
|
||||
{
|
||||
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;
|
||||
imassm_mesg.cmd = LINKS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHO(char* mask, bool oper)
|
||||
{
|
||||
static char* operator= "o";
|
||||
if (oper && mask == NULL) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = (oper) ? operator: NULL;
|
||||
imassm_mesg.cmd = WHO;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHOIS(char* target, char* mask)
|
||||
{
|
||||
if (mask == NULL) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = (target == NULL) ? mask : target;
|
||||
imassm_mesg.args[1] = (target == NULL) ? NULL : mask;
|
||||
imassm_mesg.cmd = WHOIS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHOWAS(char* nick, char* count, char* target)
|
||||
{
|
||||
if (nick == NULL || (target != NULL && count == NULL)) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = count;
|
||||
imassm_mesg.args[2] = target;
|
||||
imassm_mesg.cmd = WHOWAS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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;
|
||||
imassm_mesg.trailing = (source != NULL && target == NULL) ? true : false;
|
||||
imassm_mesg.cmd = PING;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_SUMMON(char* user, char* target, char* channel)
|
||||
{
|
||||
if (user == NULL || (channel != NULL && target == NULL)) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.args[2] = channel;
|
||||
imassm_mesg.cmd = SUMMON;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_USERHOST(char* users[])
|
||||
{
|
||||
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];
|
||||
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;
|
||||
clear_assm();
|
||||
for (unsigned int i = 0; i < 14 && users[i] != NULL; i++) { imassm_mesg.args[i] = users[i]; }
|
||||
imassm_mesg.cmd = ISON;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
|
|
@ -16,22 +16,95 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/mappings.h"
|
||||
#include "../include/types.h"
|
||||
#include "misc.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef UIRC_GUARD_PRIVATE_ASSEMBLERS
|
||||
#define UIRC_GUARD_PRIVATE_ASSEMBLERS
|
||||
signed long Assm_mesg(char* buf, IRC_Message* in, size_t len);
|
||||
#ifndef UIRC_GUARD_ASSEMBLERS
|
||||
#define UIRC_GUARD_ASSEMBLERS
|
||||
|
||||
signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig);
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
signed long Assm_tags(char* buf, IRC_Tags* in, size_t len);
|
||||
#endif /* UIRC_IRCV3*/
|
||||
|
||||
signed long Assm_mesg(char* buf, IRC_Message* in, size_t len);
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
static IRC_Message imassm_mesg;
|
||||
void clear_assm(void);
|
||||
|
||||
IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req);
|
||||
IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes);
|
||||
IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask);
|
||||
IRC_Message* Assm_cmd_WHO(char* mask, bool oper);
|
||||
IRC_Message* Assm_cmd_WHOIS(char* target, char* mask);
|
||||
IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target);
|
||||
IRC_Message* Assm_cmd_PING(char* source, char* target);
|
||||
IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel);
|
||||
IRC_Message* Assm_cmd_USERHOST(char* users[]);
|
||||
IRC_Message* Assm_cmd_ISON(char* users[]);
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
||||
#define Assm_cmd_REHASH() Assm_AUTO(REHASH, false, (char*[]) { NULL }, 0)
|
||||
#define Assm_cmd_DIE() Assm_AUTO(DIE, false, (char*[]) { NULL }, 0)
|
||||
#define Assm_cmd_RESTART() Assm_AUTO(RESTART, false, (char*[]) { NULL }, 0)
|
||||
|
||||
#define Assm_cmd_QUIT(message) Assm_AUTO(QUIT, true, (char*[]) { message, NULL }, 0)
|
||||
#define Assm_cmd_MOTD(target) Assm_AUTO(MOTD, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_VERSION(target) Assm_AUTO(VERSION, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_TIME(target) Assm_AUTO(TIME, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_TRACE(target) Assm_AUTO(TRACE, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_ADMIN(target) Assm_AUTO(ADMIN, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_INFO(target) Assm_AUTO(INFO, false, (char*[]) { target, NULL }, 0)
|
||||
#define Assm_cmd_AWAY(message) Assm_AUTO(AWAY, false, (char*[]) { message, NULL }, 0)
|
||||
|
||||
#define Assm_cmd_PASS(password) Assm_AUTO(PASS, true, (char*[]) { password, NULL }, 1)
|
||||
#define Assm_cmd_ERROR(message) Assm_AUTO(ERROR, true, (char*[]) { message, NULL }, 1)
|
||||
#define Assm_cmd_WALLOPS(text) Assm_AUTO(WALLOPS, true, (char*[]) { text, NULL }, 1)
|
||||
#define Assm_cmd_NICK(nickname) Assm_AUTO(NICK, false, (char*[]) { nickname, NULL }, 1)
|
||||
#define Assm_cmd_USERS(target) Assm_AUTO(USERS, false, (char*[]) { target, NULL }, 1)
|
||||
|
||||
#define Assm_cmd_NAMES(channels, target) Assm_AUTO(NAMES, false, (char*[]) { channels, target, NULL }, 0)
|
||||
#define Assm_cmd_LIST(channels, target) Assm_AUTO(LIST, false, (char*[]) { channels, target, NULL }, 0)
|
||||
#define Assm_cmd_LUSERS(mask, target) Assm_AUTO(LUSERS, false, (char*[]) { mask, target, NULL }, 0)
|
||||
#define Assm_cmd_STATS(query, target) Assm_AUTO(STATS, false, (char*[]) { query, target, NULL }, 0)
|
||||
#define Assm_cmd_SERVLIST(mask, type) Assm_AUTO(SERVLIST, false, (char*[]) { mask, type, NULL }, 0)
|
||||
|
||||
#define Assm_cmd_JOIN(channels, keys) Assm_AUTO(JOIN, false, (char*[]) { channels, keys, NULL }, 1)
|
||||
#define Assm_cmd_PART(channel, message) Assm_AUTO(PART, false, (char*[]) { channel, message, NULL }, 1)
|
||||
/* NOTE: Use a non-NULL address (pointing at a "\0") as the topic to clear it and use a NULL address to check it
|
||||
* Blame the protocol, not this >:C */
|
||||
#define Assm_cmd_TOPIC(channel, topic) Assm_AUTO(TOPIC, true, (char*[]) { channel, topic, NULL }, 1)
|
||||
#define Assm_cmd_PONG(source, target) Assm_AUTO(PONG, true, (char*[]) { source, target, NULL }, 1)
|
||||
|
||||
#define Assm_cmd_OPER(name, password) Assm_AUTO(OPER, true, (char*[]) { name, password, NULL }, 2)
|
||||
#define Assm_cmd_SQUIT(server, comment) Assm_AUTO(SQUIT, true, (char*[]) { server, comment, NULL }, 2)
|
||||
#define Assm_cmd_PRIVMSG(target, message) Assm_AUTO(PRIVMSG, true, (char*[]) { target, message, NULL }, 2)
|
||||
#define Assm_cmd_NOTICE(target, text) Assm_AUTO(NOTICE, true, (char*[]) { target, text, NULL }, 2)
|
||||
#define Assm_cmd_SQUERY(servicename, text) Assm_AUTO(SQUERY, true, (char*[]) { servicename, text, NULL }, 2)
|
||||
#define Assm_cmd_KILL(nick, comment) Assm_AUTO(KILL, true, (char*[]) { nick, comment, NULL }, 2)
|
||||
#define Assm_cmd_INVITE(nick, channel) Assm_AUTO(INVITE, false, (char*[]) { nick, channel, NULL }, 2)
|
||||
|
||||
#define Assm_cmd_MODE(nickname, modes, modeparams) Assm_AUTO(MODE, false, (char*[]) { nickname, modes, modeparams, NULL }, 1)
|
||||
|
||||
#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)
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
#define Assm_cmd_CAP_END() Assm_AUTO(CAP, false, (char*[]) { "END", NULL }, 0)
|
||||
#define Assm_cmd_CAP_LIST() Assm_AUTO(CAP, false, (char*[]) { "LIST", NULL }, 0)
|
||||
|
||||
#define Assm_cmd_CAP_LS(version) Assm_AUTO(CAP, false, (char*[]) { "LS", version, NULL }, 0)
|
||||
#define Assm_cmd_CAP_REQ(caps) Assm_AUTO(CAP, true, (char*[]) { "REQ", caps, NULL }, 1)
|
||||
|
||||
#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 /* UIRC_IRCV3 */
|
||||
|
||||
signed long Assm_user(char* buf, IRC_User* in, size_t len, bool useorig);
|
||||
#endif /* UIRC_GUARD_PRIVATE_ASSEMBLERS */
|
||||
#endif /* UIRC_GUARD_ASSEMBLERS */
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "capabilities.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const char* const IRC_v3_Caps[] = {
|
||||
[CAP_ACCOUNT_NOTIFY] = "account-notify",
|
||||
[CAP_ACCOUNT_TAG] = "account-tag",
|
||||
[CAP_AWAY_NOTIFY] = "away-notify",
|
||||
[CAP_BATCH] = "batch",
|
||||
[CAP_CAP_NOTIFY] = "cap-notify",
|
||||
[CAP_CHANNEL_RENAME] = "channel-rename",
|
||||
[CAP_CHGHOST] = "chghost",
|
||||
[CAP_ECHO_MESSAGE] = "echo-message",
|
||||
[CAP_EXTENDED_JOIN] = "extended-join",
|
||||
[CAP_INVITE_NOTIFY] = "invite-notify",
|
||||
[CAP_LABELED_RESPONSE] = "labeled-response",
|
||||
[CAP_MESSAGE_TAGS] = "message-tags",
|
||||
[CAP_MONITOR] = "monitor",
|
||||
[CAP_MULTI_PREFIX] = "multi-prefix",
|
||||
[CAP_MULTILINE] = "multiline",
|
||||
[CAP_SASL] = "sasl",
|
||||
[CAP_SERVER_TIME] = "server-time",
|
||||
[CAP_SETNAME] = "setname",
|
||||
[CAP_TLS] = "tls",
|
||||
[CAP_USERHOST_IN_NAMES] = "userhost-in-names",
|
||||
};
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
int
|
||||
Tok_CAPS(char* caps)
|
||||
{
|
||||
int temp = 0;
|
||||
char* cur = NULL;
|
||||
if ((cur = strtok(caps, " ")) != NULL) {
|
||||
do {
|
||||
for (int i = 1; (unsigned long) i < (sizeof(IRC_v3_Caps) / sizeof(*IRC_v3_Caps)); i++) {
|
||||
if (strcmp(IRC_v3_Caps[i], cur) == 0) {
|
||||
temp |= CAPBIT(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while ((cur = strtok(NULL, " ")) != NULL);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_CAPABILITIES
|
||||
#define UIRC_GUARD_CAPABILITIES
|
||||
|
||||
/* IRCv3 Supported features bits */
|
||||
enum caps {
|
||||
CAP_ACCOUNT_NOTIFY = 1,
|
||||
CAP_ACCOUNT_TAG = 2,
|
||||
CAP_AWAY_NOTIFY = 3,
|
||||
CAP_BATCH = 4,
|
||||
CAP_CAP_NOTIFY = 5,
|
||||
CAP_CHANNEL_RENAME = 6,
|
||||
CAP_CHGHOST = 7,
|
||||
CAP_ECHO_MESSAGE = 8,
|
||||
CAP_EXTENDED_JOIN = 9,
|
||||
CAP_INVITE_NOTIFY = 10,
|
||||
CAP_LABELED_RESPONSE = 11,
|
||||
CAP_MESSAGE_TAGS = 12,
|
||||
CAP_MONITOR = 13,
|
||||
CAP_MULTI_PREFIX = 14,
|
||||
CAP_MULTILINE = 15,
|
||||
CAP_SASL = 16,
|
||||
CAP_SERVER_TIME = 17,
|
||||
CAP_SETNAME = 18,
|
||||
CAP_TLS = 19,
|
||||
CAP_USERHOST_IN_NAMES = 20,
|
||||
};
|
||||
#define CAPBIT(cap) (1 << (cap))
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
int Tok_CAPS(char* caps);
|
||||
#endif /* UIRC_HELPERS */
|
||||
extern const char* const IRC_v3_Caps[];
|
||||
|
||||
#endif /* UIRC_GUARD_CAPABILITIES */
|
||||
|
|
@ -15,7 +15,8 @@
|
|||
* 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"
|
||||
|
||||
#include "commands.h"
|
||||
|
||||
const char* const IRC_Cmds[] = { [ADMIN] = "ADMIN", [AWAY] = "AWAY", [CONNECT] = "CONNECT", [DIE] = "DIE",
|
||||
[ERROR] = "ERROR", [INFO] = "INFO", [INVITE] = "INVITE", [ISON] = "ISON",
|
||||
|
@ -36,87 +37,3 @@ const char* const IRC_Cmds[] = { [ADMIN] = "ADMIN", [AWAY] = "AWAY", [
|
|||
[SETNAME] = "SETNAME", [WARN] = "WARN", [WEBIRC] = "WEBIRC"
|
||||
#endif /* UIRC_IRCV3 */
|
||||
};
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
const char* const IRC_v3_Caps[] = {
|
||||
[CAP_ACCOUNT_NOTIFY] = "account-notify",
|
||||
[CAP_ACCOUNT_TAG] = "account-tag",
|
||||
[CAP_AWAY_NOTIFY] = "away-notify",
|
||||
[CAP_BATCH] = "batch",
|
||||
[CAP_CAP_NOTIFY] = "cap-notify",
|
||||
[CAP_CHANNEL_RENAME] = "channel-rename",
|
||||
[CAP_CHGHOST] = "chghost",
|
||||
[CAP_ECHO_MESSAGE] = "echo-message",
|
||||
[CAP_EXTENDED_JOIN] = "extended-join",
|
||||
[CAP_INVITE_NOTIFY] = "invite-notify",
|
||||
[CAP_LABELED_RESPONSE] = "labeled-response",
|
||||
[CAP_MESSAGE_TAGS] = "message-tags",
|
||||
[CAP_MONITOR] = "monitor",
|
||||
[CAP_MULTI_PREFIX] = "multi-prefix",
|
||||
[CAP_MULTILINE] = "multiline",
|
||||
[CAP_SASL] = "sasl",
|
||||
[CAP_SERVER_TIME] = "server-time",
|
||||
[CAP_SETNAME] = "setname",
|
||||
[CAP_TLS] = "tls",
|
||||
[CAP_USERHOST_IN_NAMES] = "userhost-in-names",
|
||||
};
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
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;
|
||||
}
|
||||
return ERR_UIRC_UNKNOWN_TOKEN;
|
||||
}
|
||||
|
||||
size_t
|
||||
safe_strcpy(char** dest, const char* src, size_t lef)
|
||||
{
|
||||
size_t cnt;
|
||||
if (lef > (cnt = strlen(src)) + 1) {
|
||||
strcpy(*dest, src);
|
||||
*dest += cnt;
|
||||
return cnt;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
safe_charcpy(char** dest, const char c, size_t lef)
|
||||
{
|
||||
if (lef > 1) {
|
||||
*(*dest)++ = c;
|
||||
**dest = '\0';
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
skip_spaces(char** addr)
|
||||
{
|
||||
for (; **addr == ' '; (*addr)++)
|
||||
;
|
||||
}
|
||||
|
||||
char*
|
||||
strtok_mr(char** addr, const char* tokens)
|
||||
{
|
||||
if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) return NULL;
|
||||
char* save = *addr;
|
||||
const char* tok = NULL;
|
||||
do {
|
||||
if (!**addr) return save;
|
||||
for (tok = tokens; *tok; tok++) {
|
||||
if (**addr == *tok) {
|
||||
**addr = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (*(*addr)++);
|
||||
return save;
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_COMMANDS
|
||||
#define UIRC_GUARD_COMMANDS
|
||||
|
||||
#define UIRC_FCMD ADMIN
|
||||
enum commands {
|
||||
ADMIN = 10,
|
||||
AWAY,
|
||||
CONNECT,
|
||||
DIE,
|
||||
ERROR,
|
||||
INFO,
|
||||
INVITE,
|
||||
ISON,
|
||||
JOIN,
|
||||
KICK,
|
||||
KILL,
|
||||
LINKS,
|
||||
LIST,
|
||||
LUSERS,
|
||||
MODE,
|
||||
MOTD,
|
||||
NAMES,
|
||||
NICK,
|
||||
NOTICE,
|
||||
OPER,
|
||||
PART,
|
||||
PASS,
|
||||
PING,
|
||||
PONG,
|
||||
PRIVMSG,
|
||||
QUIT,
|
||||
REHASH,
|
||||
RESTART,
|
||||
SERVER,
|
||||
SERVICE,
|
||||
SERVLIST,
|
||||
SQUERY,
|
||||
SQUIT,
|
||||
STATS,
|
||||
SUMMON,
|
||||
TIME,
|
||||
TOPIC,
|
||||
TRACE,
|
||||
USER,
|
||||
USERHOST,
|
||||
USERS,
|
||||
VERSION,
|
||||
WALLOPS,
|
||||
WHO,
|
||||
WHOIS,
|
||||
WHOWAS,
|
||||
#ifdef UIRC_IRCV3
|
||||
ACC, /* https://github.com/ircv3/ircv3-specifications/pull/276 */
|
||||
ACCOUNT, /* https://ircv3.net/specs/extensions/account-notify-3.1 */
|
||||
ACK, /* https://ircv3.net/specs/extensions/labeled-response */
|
||||
AUTHENTICATE, /* https://ircv3.net/specs/extensions/sasl-3.1 */
|
||||
BATCH, /* https://ircv3.net/specs/extensions/batch-3.2 */
|
||||
CAP, /* https://ircv3.net/specs/core/capability-negotiation */
|
||||
CHGHOST, /* https://ircv3.net/specs/extensions/chghost-3.2 */
|
||||
FAIL, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
MONITOR, /* https://ircv3.net/specs/core/monitor-3.2 */
|
||||
NOTE, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
RENAME, /* https://github.com/ircv3/ircv3-specifications/pull/420 */
|
||||
RESUME, /* https://github.com/ircv3/ircv3-specifications/pull/306 */
|
||||
SETNAME, /* https://ircv3.net/specs/extensions/setname */
|
||||
WARN, /* https://ircv3.net/specs/extensions/standard-replies */
|
||||
WEBIRC, /* https://ircv3.net/specs/extensions/webirc */
|
||||
#define UIRC_LCMD WEBIRC
|
||||
#else /* UIRC_IRCV3 */
|
||||
#define UIRC_LCMD WHOWAS
|
||||
#endif /* UIRC_IRCV3 */
|
||||
};
|
||||
extern const char* const IRC_Cmds[];
|
||||
|
||||
#endif /* UIRC_GUARD_COMMANDS */
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "converters.h"
|
||||
|
||||
#include "commands.h"
|
||||
#include "errors.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
signed short
|
||||
Ircmd_stoi(const 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;
|
||||
}
|
||||
return ERR_UIRC_UNKNOWN_TOKEN;
|
||||
}
|
|
@ -16,7 +16,9 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "functions.h"
|
||||
#include "helpers.h"
|
||||
#include "mappings.h"
|
||||
#include "types.h"
|
||||
#ifndef UIRC_GUARD_CONVERTERS
|
||||
#define UIRC_GUARD_CONVERTERS
|
||||
|
||||
signed short Ircmd_stoi(const char* str);
|
||||
|
||||
#endif /* UIRC_GUARD_CONVERTERS */
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_ERRORS
|
||||
#define UIRC_GUARD_ERRORS
|
||||
|
||||
enum uirc_errors {
|
||||
ERR_UIRC_GENERIC = -1,
|
||||
ERR_UIRC_NULL_ARGS = -2,
|
||||
ERR_UIRC_INVALID_FORMAT = -3,
|
||||
ERR_UIRC_BUFFER_ERR = -4,
|
||||
ERR_UIRC_UNKNOWN_TOKEN = -5,
|
||||
ERR_UIRC_VAL_FAILED = -10,
|
||||
};
|
||||
|
||||
#endif /* UIRC_GUARD_ERRORS */
|
||||
|
182
src/helpers.c
182
src/helpers.c
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <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));
|
||||
}
|
||||
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;
|
||||
imassm_mesg.trailing = trailing;
|
||||
imassm_mesg.cmd = cmd;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
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();
|
||||
static char local_mode[2];
|
||||
snprintf(local_mode, 2, "%i", modes);
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = local_mode;
|
||||
imassm_mesg.args[2] = RESERVED;
|
||||
imassm_mesg.args[3] = realname;
|
||||
imassm_mesg.trailing = true;
|
||||
imassm_mesg.cmd = USER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_LINKS(char* remoteserv, char* servmask)
|
||||
{
|
||||
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;
|
||||
imassm_mesg.cmd = LINKS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHO(char* mask, bool oper)
|
||||
{
|
||||
static char* operator= "o";
|
||||
if (oper && mask == NULL) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = (oper) ? operator: NULL;
|
||||
imassm_mesg.cmd = WHO;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHOIS(char* target, char* mask)
|
||||
{
|
||||
if (mask == NULL) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = (target == NULL) ? mask : target;
|
||||
imassm_mesg.args[1] = (target == NULL) ? NULL : mask;
|
||||
imassm_mesg.cmd = WHOIS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_WHOWAS(char* nick, char* count, char* target)
|
||||
{
|
||||
if (nick == NULL || (target != NULL && count == NULL)) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = count;
|
||||
imassm_mesg.args[2] = target;
|
||||
imassm_mesg.cmd = WHOWAS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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;
|
||||
imassm_mesg.trailing = (source != NULL && target == NULL) ? true : false;
|
||||
imassm_mesg.cmd = PING;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
IRC_Message*
|
||||
Assm_cmd_SUMMON(char* user, char* target, char* channel)
|
||||
{
|
||||
if (user == NULL || (channel != NULL && target == NULL)) return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.args[2] = channel;
|
||||
imassm_mesg.cmd = SUMMON;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message*
|
||||
Assm_cmd_USERHOST(char* users[])
|
||||
{
|
||||
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];
|
||||
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;
|
||||
clear_assm();
|
||||
for (unsigned int i = 0; i < 14 && users[i] != NULL; i++) { imassm_mesg.args[i] = users[i]; }
|
||||
imassm_mesg.cmd = ISON;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
/* Use with WHOIS/LINKS
|
||||
* (stands for first argument optional)
|
||||
* [ <optarg> ] <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 temp = 0;
|
||||
char* cur = NULL;
|
||||
if ((cur = strtok(caps, " ")) != NULL) {
|
||||
do {
|
||||
for (int i = 1; (unsigned long) i < (sizeof(IRC_v3_Caps) / sizeof(*IRC_v3_Caps)); i++) {
|
||||
if (strcmp(IRC_v3_Caps[i], cur) == 0) {
|
||||
temp |= CAPBIT(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while ((cur = strtok(NULL, " ")) != NULL);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_GUARD_PRIVATE_HELPERS
|
||||
#define UIRC_GUARD_PRIVATE_HELPERS
|
||||
extern char* RESERVED;
|
||||
void clear_assm(void);
|
||||
|
||||
IRC_Message* Assm_AUTO(IRC_Command cmd, bool trailing, char** args, int req);
|
||||
|
||||
IRC_Message* Assm_cmd_USER(char* user, char* realname, int modes);
|
||||
IRC_Message* Assm_cmd_LINKS(char* remoteserv, char* servmask);
|
||||
IRC_Message* Assm_cmd_WHO(char* mask, bool oper);
|
||||
IRC_Message* Assm_cmd_WHOIS(char* target, char* mask);
|
||||
IRC_Message* Assm_cmd_WHOWAS(char* nick, char* count, char* target);
|
||||
IRC_Message* Assm_cmd_PING(char* source, char* target);
|
||||
IRC_Message* Assm_cmd_SUMMON(char* user, char* target, char* channel);
|
||||
IRC_Message* Assm_cmd_USERHOST(char* users[]);
|
||||
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 /* UIRC_GUARD_PRIVATE_HELPERS */
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
size_t
|
||||
safe_strcpy(char** dest, const char* src, size_t lef)
|
||||
{
|
||||
size_t cnt;
|
||||
if (lef > (cnt = strlen(src)) + 1) {
|
||||
strcpy(*dest, src);
|
||||
*dest += cnt;
|
||||
return cnt;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
safe_charcpy(char** dest, const char c, size_t lef)
|
||||
{
|
||||
if (lef > 1) {
|
||||
*(*dest)++ = c;
|
||||
**dest = '\0';
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef UIRC_GUARD_MEMORY
|
||||
#define UIRC_GUARD_MEMORY
|
||||
|
||||
size_t safe_strcpy(char** dest, const char* src, size_t lef);
|
||||
bool safe_charcpy(char** dest, char c, size_t lef);
|
||||
|
||||
#endif /* UIRC_GUARD_MEMORY */
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_MODES
|
||||
#define UIRC_GUARD_MODES
|
||||
|
||||
/* Mode bitmask values */
|
||||
#define MBMASK_WALLOPS 1 << 1 /* 010 */
|
||||
#define MBMASK_INVIS 1 << 2 /* 100 */
|
||||
|
||||
#endif /* UIRC_GUARD_MODES */
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UIRC_GUARD_REPLIES
|
||||
#define UIRC_GUARD_REPLIES
|
||||
|
||||
enum replies {
|
||||
RPL_WELCOME = 1,
|
||||
RPL_YOURHOST = 2,
|
||||
RPL_CREATED = 3,
|
||||
RPL_MYINFO = 4,
|
||||
RPL_BOUNCE = 5,
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
/* TO IRCv3 WG:
|
||||
* Please, stop complicating implementations
|
||||
* Get people in the WG that actually care about the protocol and understand why and how standards are written
|
||||
*
|
||||
* TO LIBRARY USERS:
|
||||
* Read the above and go speak with them, or just don't use IRCv3 :)
|
||||
*/
|
||||
RPL_ISUPPORT = 5,
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
RPL_TRACELINK = 200,
|
||||
RPL_TRACECONNECTING = 201,
|
||||
RPL_TRACEHANDSHAKE = 202,
|
||||
RPL_TRACEUNKNOWN = 203,
|
||||
RPL_TRACEOPERATOR = 204,
|
||||
RPL_TRACEUSER = 205,
|
||||
RPL_TRACESERVER = 206,
|
||||
RPL_TRACENEWTYPE = 208,
|
||||
RPL_STATSLINKINFO = 211,
|
||||
RPL_STATSCOMMANDS = 212,
|
||||
RPL_STATSCLINE = 213,
|
||||
RPL_STATSNLINE = 214,
|
||||
RPL_STATSILINE = 215,
|
||||
RPL_STATSKLINE = 216,
|
||||
RPL_STATSYLINE = 218,
|
||||
RPL_ENDOFSTATS = 219,
|
||||
RPL_UMODEIS = 221,
|
||||
RPL_STATSLLINE = 241,
|
||||
RPL_STATSUPTIME = 242,
|
||||
RPL_STATSOLINE = 243,
|
||||
RPL_STATSHLINE = 244,
|
||||
RPL_LUSERCLIENT = 251,
|
||||
RPL_LUSEROP = 252,
|
||||
RPL_LUSERUNKNOWN = 253,
|
||||
RPL_LUSERCHANNELS = 254,
|
||||
RPL_LUSERME = 255,
|
||||
RPL_ADMINME = 256,
|
||||
RPL_ADMINLOC1 = 257,
|
||||
RPL_ADMINLOC2 = 258,
|
||||
RPL_ADMINEMAIL = 259,
|
||||
RPL_TRACELOG = 261,
|
||||
RPL_NONE = 300,
|
||||
RPL_AWAY = 301,
|
||||
RPL_USERHOST = 302,
|
||||
RPL_ISON = 303,
|
||||
RPL_UNAWAY = 305,
|
||||
RPL_NOWAWAY = 306,
|
||||
RPL_WHOISUSER = 311,
|
||||
RPL_WHOISSERVER = 312,
|
||||
RPL_WHOISOPERATOR = 313,
|
||||
RPL_WHOWASUSER = 314,
|
||||
RPL_ENDOFWHO = 315,
|
||||
RPL_WHOISIDLE = 317,
|
||||
RPL_ENDOFWHOIS = 318,
|
||||
RPL_WHOISCHANNELS = 319,
|
||||
RPL_LISTSTART = 321,
|
||||
RPL_LIST = 322,
|
||||
RPL_LISTEND = 323,
|
||||
RPL_CHANNELMODEIS = 324,
|
||||
RPL_NOTOPIC = 331,
|
||||
RPL_TOPIC = 332,
|
||||
RPL_INVITING = 341,
|
||||
RPL_SUMMONING = 342,
|
||||
RPL_VERSION = 351,
|
||||
RPL_WHOREPLY = 352,
|
||||
RPL_NAMREPLY = 353,
|
||||
RPL_LINKS = 364,
|
||||
RPL_ENDOFLINKS = 365,
|
||||
RPL_ENDOFNAMES = 366,
|
||||
RPL_BANLIST = 367,
|
||||
RPL_ENDOFBANLIST = 368,
|
||||
RPL_ENDOFWHOWAS = 369,
|
||||
RPL_INFO = 371,
|
||||
RPL_MOTD = 372,
|
||||
RPL_ENDOFINFO = 374,
|
||||
RPL_MOTDSTART = 375,
|
||||
RPL_ENDOFMOTD = 376,
|
||||
RPL_YOUREOPER = 381,
|
||||
RPL_REHASHING = 382,
|
||||
RPL_TIME = 391,
|
||||
RPL_USERSSTART = 392,
|
||||
RPL_USERS = 393,
|
||||
RPL_ENDOFUSERS = 394,
|
||||
RPL_NOUSERS = 395,
|
||||
|
||||
ERR_NOSUCHNICK = 401,
|
||||
ERR_NOSUCHSERVER = 402,
|
||||
ERR_NOSUCHCHANNEL = 403,
|
||||
ERR_CANNOTSENDTOCHAN = 404,
|
||||
ERR_TOOMANYCHANNELS = 405,
|
||||
ERR_WASNOSUCHNICK = 406,
|
||||
ERR_TOOMANYTARGETS = 407,
|
||||
ERR_NOORIGIN = 409,
|
||||
ERR_NORECIPIENT = 411,
|
||||
ERR_NOTEXTTOSEND = 412,
|
||||
ERR_NOTOPLEVEL = 413,
|
||||
ERR_WILDTOPLEVEL = 414,
|
||||
ERR_UNKNOWNCOMMAND = 421,
|
||||
ERR_NOMOTD = 422,
|
||||
ERR_NOADMININFO = 423,
|
||||
ERR_FILEERROR = 424,
|
||||
ERR_NONICKNAMEGIVEN = 431,
|
||||
ERR_ERRONEUSNICKNAME = 432,
|
||||
ERR_NICKNAMEINUSE = 433,
|
||||
ERR_NICKCOLLISION = 436,
|
||||
ERR_USERNOTINCHANNEL = 441,
|
||||
ERR_NOTONCHANNEL = 442,
|
||||
ERR_USERONCHANNEL = 443,
|
||||
ERR_NOLOGIN = 444,
|
||||
ERR_SUMMONDISABLED = 445,
|
||||
ERR_USERSDISABLED = 446,
|
||||
ERR_NOTREGISTERED = 451,
|
||||
ERR_NEEDMOREPARAMS = 461,
|
||||
ERR_ALREADYREGISTRED = 462,
|
||||
ERR_NOPERMFORHOST = 463,
|
||||
ERR_PASSWDMISMATCH = 464,
|
||||
ERR_YOUREBANNEDCREEP = 465,
|
||||
ERR_KEYSET = 467,
|
||||
ERR_CHANNELISFULL = 471,
|
||||
ERR_UNKNOWNMODE = 472,
|
||||
ERR_INVITEONLYCHAN = 473,
|
||||
ERR_BANNEDFROMCHAN = 474,
|
||||
ERR_BADCHANNELKEY = 475,
|
||||
ERR_NOPRIVILEGES = 481,
|
||||
ERR_CHANOPRIVSNEEDED = 482,
|
||||
ERR_CANTKILLSERVER = 483,
|
||||
ERR_NOOPERHOST = 491,
|
||||
ERR_UMODEUNKNOWNFLAG = 501,
|
||||
ERR_USERSDONTMATCH = 502,
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
/* https://ircv3.net/registry */
|
||||
RPL_STARTTLS = 670,
|
||||
ERR_STARTTLS = 691,
|
||||
|
||||
RPL_MONONLINE = 730,
|
||||
RPL_MONOFFLINE = 731,
|
||||
RPL_MONLIST = 732,
|
||||
RPL_ENDOFMONLIST = 733,
|
||||
ERR_MOLISTFULL = 734,
|
||||
|
||||
RPL_LOGGEDIN = 900,
|
||||
RPL_LOGGEDOUT = 901,
|
||||
ERR_NICKLOCKED = 902,
|
||||
RPL_SASLSUCCESS = 903,
|
||||
ERR_SASLFAIL = 904,
|
||||
ERR_SASLTOOLONG = 905,
|
||||
ERR_SASLABORTED = 906,
|
||||
ERR_SASLALREADY = 907,
|
||||
ERR_SASLMECHS = 908,
|
||||
#endif /* UIRC_IRCV3 */
|
||||
};
|
||||
|
||||
#endif /* UIRC_GUARD_REPLIES */
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
skip_spaces(char** addr)
|
||||
{
|
||||
for (; **addr == ' '; (*addr)++)
|
||||
;
|
||||
}
|
||||
|
||||
char*
|
||||
strtok_mr(char** addr, const char* tokens)
|
||||
{
|
||||
if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) return NULL;
|
||||
char* save = *addr;
|
||||
const char* tok = NULL;
|
||||
do {
|
||||
if (!**addr) return save;
|
||||
for (tok = tokens; *tok; tok++) {
|
||||
if (**addr == *tok) {
|
||||
**addr = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (*(*addr)++);
|
||||
return save;
|
||||
}
|
||||
|
|
@ -16,7 +16,11 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "taghelpers.h"
|
||||
#ifndef UIRC_GUARD_STRING
|
||||
#define UIRC_GUARD_STRING
|
||||
|
||||
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)); }
|
||||
void skip_spaces(char** addr);
|
||||
char* strtok_mr(char** addr, const char* tokens);
|
||||
|
||||
#endif /* UIRC_GUARD_STRING */
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tags.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
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));
|
||||
}
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
|
@ -16,14 +16,22 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef UIRC_GUARD_PRIVATE_TAGHELPERS
|
||||
#define UIRC_GUARD_PRIVATE_TAGHELPERS
|
||||
#ifndef UIRC_GUARD_TAGS
|
||||
#define UIRC_GUARD_TAGS
|
||||
|
||||
struct tagmapping {
|
||||
const char* const name;
|
||||
IRC_Tag* assg;
|
||||
};
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
size_t Assm_tag_timestamp(char* buf, size_t len, time_t time);
|
||||
#endif /* UIRC_GUARD_PRIVATE_TAGHELPERS */
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
||||
#endif /* UIRC_GUARD_TAGS */
|
144
src/tokenizers.c
144
src/tokenizers.c
|
@ -15,64 +15,21 @@
|
|||
* 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;
|
||||
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;
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
skip_spaces(&progr);
|
||||
#endif /* UIRC_IRCV3 */
|
||||
if (*progr == ':') {
|
||||
char* prefix;
|
||||
if ((prefix = strtok_mr(&progr, " ")) != NULL) {
|
||||
if ((ret = Tok_user(prefix, &out->name, false)) < 0) return ret;
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
#include "commands.h"
|
||||
#include "converters.h"
|
||||
#include "errors.h"
|
||||
#include "string.h"
|
||||
#include "tags.h"
|
||||
#include "types.h"
|
||||
|
||||
skip_spaces(&progr);
|
||||
|
||||
if (isalnum(*progr) && (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;
|
||||
out->cmd = (IRC_Command) temp;
|
||||
} else {
|
||||
for (size_t l = 0; command[l]; l++) {
|
||||
if (!isdigit(command[l])) return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
out->cmd = (IRC_Command) atoi(command);
|
||||
}
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
|
||||
skip_spaces(&progr);
|
||||
|
||||
short i;
|
||||
for (i = 0; i < 15 && *progr;) {
|
||||
if (i == 14 || *progr == ':') {
|
||||
out->args[i++] = (*progr == ':') ? progr + 1 : progr;
|
||||
out->trailing = true;
|
||||
break;
|
||||
} else {
|
||||
if ((out->args[i++] = strtok_mr(&progr, " ")) == NULL) return ERR_UIRC_INVALID_FORMAT;
|
||||
skip_spaces(&progr);
|
||||
}
|
||||
}
|
||||
out->args[i] = NULL;
|
||||
return 1;
|
||||
}
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
signed int
|
||||
|
@ -133,3 +90,80 @@ Tok_user(char* str, IRC_User* out, bool useorig)
|
|||
return 1;
|
||||
}
|
||||
|
||||
signed int
|
||||
Tok_mesg(char* str, IRC_Message* out)
|
||||
{
|
||||
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;
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
skip_spaces(&progr);
|
||||
#endif /* UIRC_IRCV3 */
|
||||
if (*progr == ':') {
|
||||
char* prefix;
|
||||
if ((prefix = strtok_mr(&progr, " ")) != NULL) {
|
||||
if ((ret = Tok_user(prefix, &out->name, false)) < 0) return ret;
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
|
||||
skip_spaces(&progr);
|
||||
|
||||
if (isalnum(*progr) && (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;
|
||||
out->cmd = (IRC_Command) temp;
|
||||
} else {
|
||||
for (size_t l = 0; command[l]; l++) {
|
||||
if (!isdigit(command[l])) return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
out->cmd = (IRC_Command) atoi(command);
|
||||
}
|
||||
} else
|
||||
return ERR_UIRC_INVALID_FORMAT;
|
||||
|
||||
skip_spaces(&progr);
|
||||
|
||||
short i;
|
||||
for (i = 0; i < 15 && *progr;) {
|
||||
if (i == 14 || *progr == ':') {
|
||||
out->args[i++] = (*progr == ':') ? progr + 1 : progr;
|
||||
out->trailing = true;
|
||||
break;
|
||||
} else {
|
||||
if ((out->args[i++] = strtok_mr(&progr, " ")) == NULL) return ERR_UIRC_INVALID_FORMAT;
|
||||
skip_spaces(&progr);
|
||||
}
|
||||
}
|
||||
out->args[i] = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
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];
|
||||
}
|
||||
/* Use with WHOIS/LINKS
|
||||
* (stands for first argument optional)
|
||||
* [ <optarg> ] <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];
|
||||
}
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
||||
|
|
|
@ -16,23 +16,24 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/mappings.h"
|
||||
#include "../include/types.h"
|
||||
#include "misc.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef UIRC_GUARD_PRIVATE_TOKENIZERS
|
||||
#define UIRC_GUARD_PRIVATE_TOKENIZERS
|
||||
signed int Tok_mesg(char* str, IRC_Message* out);
|
||||
#ifndef UIRC_GUARD_TOKENIZERS
|
||||
#define UIRC_GUARD_TOKENIZERS
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
signed int Tok_tags(char* str, IRC_Tags* out);
|
||||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
signed int Tok_user(char* str, IRC_User* out, bool useorig);
|
||||
#endif /* UIRC_GUARD_PRIVATE_TOKENIZERS */
|
||||
signed int Tok_mesg(char* str, IRC_Message* out);
|
||||
|
||||
#ifdef UIRC_HELPERS
|
||||
void Tok_cmd_PING(IRC_Message* mesg, char** source, char** target);
|
||||
void Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg);
|
||||
#endif /* UIRC_HELPERS */
|
||||
|
||||
#endif /* UIRC_GUARD_TOKENIZERS */
|
||||
|
||||
|
|
|
@ -17,15 +17,17 @@
|
|||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef UIRC_GUARD_TYPES
|
||||
#define UIRC_GUARD_TYPES
|
||||
|
||||
typedef unsigned short IRC_Command;
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
typedef struct {
|
||||
char* value; /* if present, it isn't NULL and if it has no value, it is "" (aka '\0') */
|
||||
char* value; /* if present, it isn't NULL and if it has no value, it is "" */
|
||||
bool clientbound;
|
||||
} IRC_Tag;
|
||||
|
||||
typedef struct {
|
||||
/* See https://ircv3.net/registry#tags for more information */
|
||||
IRC_Tag account, batch, label, msgid, multiline_concat, time, typing, react, reply;
|
||||
|
@ -33,14 +35,8 @@ typedef struct {
|
|||
#endif /* UIRC_IRCV3 */
|
||||
|
||||
typedef struct {
|
||||
char* nick, *user, *host, *orig, *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.
|
||||
* nick!user%orig@host */
|
||||
|
||||
typedef unsigned short IRC_Command;
|
||||
|
||||
typedef struct {
|
||||
#ifdef UIRC_IRCV3
|
||||
IRC_Tags tags;
|
|
@ -16,26 +16,20 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/mappings.h"
|
||||
#include "../include/types.h"
|
||||
#include "assemblers.h"
|
||||
#include "commands.h"
|
||||
#include "converters.h"
|
||||
#include "errors.h"
|
||||
#include "modes.h"
|
||||
#include "replies.h"
|
||||
#include "tokenizers.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef UIRC_GUARD_PRIVATE_MISC
|
||||
#define UIRC_GUARD_PRIVATE_MISC
|
||||
#ifdef UIRC_VALIDATORS
|
||||
#include "validators.h"
|
||||
#endif /* UIRC_VALIDATORS */
|
||||
|
||||
#ifdef UIRC_IRCV3
|
||||
struct tagmapping {
|
||||
const char* const name;
|
||||
IRC_Tag* assg;
|
||||
};
|
||||
#include "capabilities.h"
|
||||
#include "tags.h"
|
||||
#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 /* UIRC_GUARD_PRIVATE_MISC */
|
||||
|
|
@ -15,20 +15,14 @@
|
|||
* 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;
|
||||
for (unsigned int i = 0; mesg->args[i] != NULL; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#include "errors.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
signed int
|
||||
Val_type_nocrlf(char* str)
|
||||
|
@ -79,3 +73,16 @@ Val_channame(char* chan)
|
|||
return 1;
|
||||
}
|
||||
|
||||
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++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,18 +16,16 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/mappings.h"
|
||||
#include "../include/types.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef UIRC_GUARD_VALIDATORS
|
||||
#define UIRC_GUARD_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 /* UIRC_GUARD_PRIVATE_VALIDATORS */
|
||||
signed int Val_mesg(IRC_Message* mesg);
|
||||
|
||||
#endif /* UIRC_GUARD_VALIDATORS */
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
macro(buildtest name source)
|
||||
add_executable(${source} ${source}.c)
|
||||
target_link_libraries(${source} uirc)
|
||||
add_test(NAME ${name} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${source})
|
||||
endmacro()
|
||||
|
||||
buildtest(Tokenizer tokenizer)
|
||||
buildtest(Overflow overflow)
|
||||
buildtest(PrefixAssembler prefixassm)
|
||||
buildtest(MessageAssembler msgassm)
|
||||
buildtest(NumericCmds numericmds)
|
||||
buildtest(IncorrectTrailing notrail)
|
||||
buildtest(SpacedArguments spacedargs)
|
||||
buildtest(StrTokMoveSave strtokmr)
|
||||
buildtest(Junk junk)
|
||||
|
||||
if ( BUILD_IRCV3 )
|
||||
buildtest(TagParser tagtok)
|
||||
buildtest(TagAssembler tagassm)
|
||||
if ( BUILD_HELPERS )
|
||||
buildtest(TimestampAssembly timestamp)
|
||||
buildtest(TagBitMaskTknzr capbitmask)
|
||||
endif()
|
||||
endif()
|
|
@ -1,11 +1,31 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/capabilities.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int temp = 0;
|
||||
int temp = 0;
|
||||
char wcps[] = "multi-prefix sasl";
|
||||
if ((temp = Tok_CAPS(wcps)) != (CAPBIT(CAP_MULTI_PREFIX) | CAPBIT(CAP_SASL))) return EXIT_FAILURE;
|
||||
char multicaps[] = "sasl echo-message echo-message";
|
||||
|
|
21
tests/junk.c
21
tests/junk.c
|
@ -1,4 +1,23 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/tokenizers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,19 +1,41 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/assemblers.h"
|
||||
#include "../src/commands.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = {0};
|
||||
IRC_Message input = {
|
||||
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,
|
||||
.args = {"(You)", "are ya winning son?", NULL},
|
||||
.trailing = true,
|
||||
.name = { .nick = "dad", .user = "dad-door", .host = "home.localhost" },
|
||||
.cmd = PRIVMSG,
|
||||
.args = { "(You)", "are ya winning son?", NULL },
|
||||
.trailing = true,
|
||||
};
|
||||
signed long res;
|
||||
if ((res = Assm_mesg(mesg, &input, 512)) <= 0) {
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/tokenizers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = ":nick!user@host QUIT arg1 ";
|
||||
IRC_Message parseout = {0};
|
||||
int res = 0;
|
||||
char mesg[513] = ":nick!user@host QUIT arg1 ";
|
||||
IRC_Message parseout = { 0 };
|
||||
int res = 0;
|
||||
if ((res = Tok_mesg(mesg, &parseout)) <= 0) {
|
||||
printf("String could not be tokenized. %i\n", res);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,15 +1,37 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/assemblers.h"
|
||||
#include "../src/replies.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = {0};
|
||||
IRC_Message input = {
|
||||
.cmd = RPL_WELCOME,
|
||||
.args = {"hello", NULL},
|
||||
.trailing = true,
|
||||
char mesg[513] = { 0 };
|
||||
IRC_Message input = {
|
||||
.cmd = RPL_WELCOME,
|
||||
.args = { "hello", NULL },
|
||||
.trailing = true,
|
||||
};
|
||||
signed long res;
|
||||
if ((res = Assm_mesg(mesg, &input, 512)) <= 0) {
|
||||
|
|
|
@ -1,23 +1,49 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/assemblers.h"
|
||||
#include "../src/commands.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
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},
|
||||
.trailing = true};
|
||||
if (Assm_mesg(mesg, &input, 512) > 0) return EXIT_FAILURE;
|
||||
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 },
|
||||
.trailing = true
|
||||
};
|
||||
signed long i;
|
||||
if ((i = Assm_mesg(mesg, &input, 512)) > 0) {
|
||||
fprintf(stderr, "Got %li instead of < 0", i);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/assemblers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = {0};
|
||||
IRC_User input = {.nick = "durov", .user = "pavel", .host = "telegram.org"};
|
||||
signed long res = 0;
|
||||
char mesg[513] = { 0 };
|
||||
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);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,18 +1,40 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/commands.h"
|
||||
#include "../src/tokenizers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define cmd "QUIT"
|
||||
#define arg1 "arg1"
|
||||
#define arg2 "arg2"
|
||||
#define cmd "QUIT"
|
||||
#define arg1 "arg1"
|
||||
#define arg2 "arg2"
|
||||
#define trailing "Finished!"
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = cmd " " arg1 " " arg2 " :" trailing;
|
||||
char mesg[513] = cmd " " arg1 " " arg2 " :" trailing;
|
||||
IRC_Message parseout;
|
||||
int res = 0;
|
||||
int res = 0;
|
||||
if ((res = Tok_mesg(mesg, &parseout)) <= 0) {
|
||||
printf("String could not be tokenized. %i\n", res);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,21 +1,41 @@
|
|||
#include "../src/misc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char* pointer = NULL;
|
||||
if (strtok_mr(&pointer, "!") != NULL) return EXIT_FAILURE;
|
||||
if (pointer != NULL) return EXIT_FAILURE;
|
||||
|
||||
char test2[] = "hello";
|
||||
pointer = test2;
|
||||
pointer = test2;
|
||||
if (strtok_mr(&pointer, "!") == NULL) return EXIT_FAILURE;
|
||||
if (*pointer != '\0') return EXIT_FAILURE;
|
||||
|
||||
char test3[] = "hi!# hello!";
|
||||
pointer = test3;
|
||||
pointer = test3;
|
||||
if (strtok_mr(&pointer, "!#") == NULL) return EXIT_FAILURE;
|
||||
if (pointer != test3 + 3) /* MUST point at # right after ! */
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/assemblers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = {0};
|
||||
IRC_Tags input = {.time = {.value = "now", .clientbound = true}, .msgid = {.value = "", .clientbound = false}};
|
||||
signed long res = 0;
|
||||
char mesg[513] = { 0 };
|
||||
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);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/tokenizers.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[513] = "@msgid=1s32;+time QUIT";
|
||||
char mesg[513] = "@msgid=1s32;+time QUIT";
|
||||
IRC_Message parseout;
|
||||
int res = 0;
|
||||
int res = 0;
|
||||
if ((res = Tok_mesg(mesg, &parseout)) <= 0) {
|
||||
printf("String could not be tokenized. %i\n", res);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/tags.h"
|
||||
#include "../src/types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char buffer[26];
|
||||
char buffer[26];
|
||||
time_t res = 1130620230;
|
||||
if (Assm_tag_timestamp(buffer, sizeof(buffer), res) && strcmp("2005-10-29T21:10:30.000Z", buffer) == 0)
|
||||
return EXIT_SUCCESS;
|
||||
if (Assm_tag_timestamp(buffer, sizeof(buffer), res) && strcmp("2005-10-29T21:10:30.000Z", buffer) == 0) return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,24 @@
|
|||
#include "../include/uirc.h"
|
||||
/*
|
||||
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../src/commands.h"
|
||||
#include "../src/tokenizers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -6,18 +26,20 @@
|
|||
#define nickname "nick"
|
||||
#define username "user"
|
||||
#define hostname "host"
|
||||
#define arg2 "Finished!"
|
||||
#define arg2 "Finished!"
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[2][513] = {
|
||||
#ifdef UIRC_IRCV3
|
||||
"@+msgid=1s32;time;+reply;account=x "
|
||||
"@+msgid=1s32;time;+reply;account=x "
|
||||
#endif
|
||||
":" nickname "!" username "@" hostname " QUIT arg1 :" arg2,
|
||||
"001 hell :sup cj"};
|
||||
IRC_Message parseout = {0};
|
||||
int res = 0;
|
||||
":" nickname "!" username "@" hostname " QUIT arg1 :" arg2,
|
||||
"001 hell :sup cj"
|
||||
};
|
||||
IRC_Message parseout = { 0 };
|
||||
int res = 0;
|
||||
if ((res = Tok_mesg(mesg[0], &parseout)) <= 0) {
|
||||
printf("String could not be tokenized. %i\n", res);
|
||||
return EXIT_FAILURE;
|
||||
|
|
Reference in New Issue