This repository has been archived on 2021-04-17. You can view files and clone it, but cannot push or open issues or pull requests.
uIRC/src/public/assemblers.h

120 lines
6.7 KiB
C

/*
* 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/>.
*/
/*! \file */
#include "types.h"
#include <sys/types.h>
#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*/
/*!
* \brief IRC_Message to string converter
*
* This assembles a IRC_Message struct to a string representation of a most size len
* The return value is either the lenght of the string or any of the uirc_errors errors
* \param[in] in IRC_Message struct that contains at least a command
* \param[in] len Maximum lenght of string
* \param[out] buf String representation of message (if successful)
* \warning in and buf SHOULD NOT be NULL, this will trigger a ASSERT so it's required to check it where needed
*/
signed long Assm_mesg(char* buf, IRC_Message* in, size_t len);
#ifdef UIRC_HELPERS
IRC_Message* Assm_AUTO(IRC_Message* imassm_mesg, IRC_Command cmd, bool trailing, char** args, int req);
IRC_Message* Assm_cmd_USER(IRC_Message* imassm_mesg, char* user, char* realname, int modes);
IRC_Message* Assm_cmd_LINKS(IRC_Message* imassm_mesg, char* remoteserv, char* servmask);
IRC_Message* Assm_cmd_WHO(IRC_Message* imassm_mesg, char* mask, bool oper);
IRC_Message* Assm_cmd_WHOIS(IRC_Message* imassm_mesg, char* target, char* mask);
IRC_Message* Assm_cmd_WHOWAS(IRC_Message* imassm_mesg, char* nick, char* count, char* target);
IRC_Message* Assm_cmd_PING(IRC_Message* imassm_mesg, char* source, char* target);
IRC_Message* Assm_cmd_SUMMON(IRC_Message* imassm_mesg, char* user, char* target, char* channel);
IRC_Message* Assm_cmd_USERHOST(IRC_Message* imassm_mesg, char* users[]);
IRC_Message* Assm_cmd_ISON(IRC_Message* imassm_mesg, 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 */
#endif /* UIRC_GUARD_ASSEMBLERS */