Build shared object and separate stuff into their specific headers, add conditional helpers building
This commit is contained in:
parent
d998c1221a
commit
2c25e69ce0
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(microirc LANGUAGES C)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic")
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/archive)
|
||||
|
||||
set(build_FILES src/uirc.c)
|
||||
if ( USE_HELPERS )
|
||||
message("Helper functions are going to be built.")
|
||||
set(build_FILES src/uirc.c src/helpers.c)
|
||||
endif()
|
||||
add_library(uirc SHARED ${build_FILES})
|
||||
set_property(TARGET uirc PROPERTY C_STANDARD 11)
|
||||
|
||||
install(TARGETS uirc DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
@ -0,0 +1,50 @@
|
|||
#ifdef UIRC_HELPERS
|
||||
#ifndef _UIRC_HELPERS_INCLUDED
|
||||
#define _UIRC_HELPERS_INCLUDED
|
||||
extern IRC_Message* Assemble_NICK(char* nick);
|
||||
extern IRC_Message* Assemble_USER(char* user, char* realname, int modes);
|
||||
extern IRC_Message* Assemble_PASS(char* password);
|
||||
extern IRC_Message* Assemble_OPER(char* name, char* password);
|
||||
extern IRC_Message* Assemble_MODE(char* nick, char* modes, char* modeparams);
|
||||
extern IRC_Message* Assemble_SERVICE(char* nickname, char* distribution, char* type, char* info);
|
||||
extern IRC_Message* Assemble_QUIT(char* mesg, IRC_User* user);
|
||||
extern IRC_Message* Assemble_SQUIT(char* server, char* comment, IRC_User* user);
|
||||
extern IRC_Message* Assemble_JOIN(char* channels, char* keys, IRC_User* user);
|
||||
extern IRC_Message* Assemble_PART(char* channel, char* message, IRC_User* user);
|
||||
extern IRC_Message* Assemble_TOPIC(char* channel, char* topic, IRC_User* user);
|
||||
extern IRC_Message* Assemble_NAMES(char* channels, char* target);
|
||||
extern IRC_Message* Assemble_LIST(char* channels, char* target);
|
||||
extern IRC_Message* Assemble_INVITE(char* nick, char* channel, IRC_User* user);
|
||||
extern IRC_Message* Assemble_KICK(char* channels, char* users, char* comment, IRC_User* user);
|
||||
extern IRC_Message* Assemble_PRIVMSG(char* target, char* message, IRC_User* source);
|
||||
extern IRC_Message* Assemble_NOTICE(char* target, char* text, IRC_User* user);
|
||||
extern IRC_Message* Assemble_MOTD(char* target);
|
||||
extern IRC_Message* Assemble_LUSERS(char* mask, char* target);
|
||||
extern IRC_Message* Assemble_VERSION(char* target);
|
||||
extern IRC_Message* Assemble_STATS(char* query, char* target);
|
||||
extern IRC_Message* Assemble_LINKS(char* remoteserv, char* servmask);
|
||||
extern IRC_Message* Assemble_TIME(char* target);
|
||||
extern IRC_Message* Assemble_CONNECT(char* target, char* port, char* remote);
|
||||
extern IRC_Message* Assemble_TRACE(char* target);
|
||||
extern IRC_Message* Assemble_ADMIN(char* target);
|
||||
extern IRC_Message* Assemble_INFO(char* target);
|
||||
extern IRC_Message* Assemble_SERVLIST(char* mask, char* type);
|
||||
extern IRC_Message* Assemble_SQUERY(char* servicename, char* text);
|
||||
extern IRC_Message* Assemble_WHO(char* mask, bool oper);
|
||||
extern IRC_Message* Assemble_WHOIS(char* target, char* mask);
|
||||
extern IRC_Message* Assemble_WHOWAS(char* nick, char* count, char* target);
|
||||
extern IRC_Message* Assemble_KILL(char* nick, char* comment);
|
||||
extern IRC_Message* Assemble_PING(char* source, char* target);
|
||||
extern IRC_Message* Assemble_PONG(char* source, char* target);
|
||||
extern IRC_Message* Assemble_ERROR(char* message);
|
||||
extern IRC_Message* Assemble_AWAY(char* mesg);
|
||||
extern IRC_Message* Assemble_REHASH(void);
|
||||
extern IRC_Message* Assemble_DIE(void);
|
||||
extern IRC_Message* Assemble_RESTART(void);
|
||||
extern IRC_Message* Assemble_SUMMON(char* user, char* target, char* channel);
|
||||
extern IRC_Message* Assemble_USERS(char* target);
|
||||
extern IRC_Message* Assemble_WALLOPS(char* text, IRC_User* source);
|
||||
extern IRC_Message* Assemble_USERHOST(char* users[], IRC_User* source);
|
||||
extern IRC_Message* Assemble_ISON(char* users[]);
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,187 @@
|
|||
#ifndef _UIRC_ENUMS_INCLUDED
|
||||
#define _UIRC_ENUMS_INCLUDED
|
||||
|
||||
#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
|
||||
|
||||
/* Mode bitmask values */
|
||||
#define MBMASK_WALLOPS 2 /* 010 */
|
||||
#define MBMASK_INVIS 4 /* 100 */
|
||||
|
||||
enum {
|
||||
PASS = 10,
|
||||
NICK,
|
||||
USER,
|
||||
SERVER,
|
||||
OPER,
|
||||
SERVICE,
|
||||
QUIT,
|
||||
SQUIT,
|
||||
JOIN,
|
||||
PART,
|
||||
MODE,
|
||||
TOPIC,
|
||||
NAMES,
|
||||
LIST,
|
||||
INVITE,
|
||||
KICK,
|
||||
VERSION,
|
||||
STATS,
|
||||
LINKS,
|
||||
TIME,
|
||||
CONNECT,
|
||||
TRACE,
|
||||
ADMIN,
|
||||
INFO,
|
||||
SERVLIST,
|
||||
SQUERY,
|
||||
PRIVMSG,
|
||||
NOTICE,
|
||||
MOTD,
|
||||
LUSERS,
|
||||
WHO,
|
||||
WHOIS,
|
||||
WHOWAS,
|
||||
KILL,
|
||||
PING,
|
||||
PONG,
|
||||
ERROR,
|
||||
AWAY,
|
||||
REHASH,
|
||||
DIE,
|
||||
RESTART,
|
||||
SUMMON,
|
||||
USERS,
|
||||
WALLOPS,
|
||||
USERHOST,
|
||||
ISON
|
||||
};
|
||||
enum {
|
||||
RPL_WELCOME = 1,
|
||||
RPL_YOURHOST = 2,
|
||||
RPL_CREATED = 3,
|
||||
RPL_MYINFO = 4,
|
||||
RPL_BOUNCE = 5,
|
||||
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
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef _UIRC_STRUCTS_INCLUDED
|
||||
#define _UIRC_STRUCTS_INCLUDED
|
||||
typedef struct uirc_tag {
|
||||
const char* value;
|
||||
bool clientbound;
|
||||
bool present;
|
||||
} IRC_Tag;
|
||||
typedef struct name {
|
||||
const char* nick;
|
||||
const char* user;
|
||||
const char* host;
|
||||
const char* realname;
|
||||
} IRC_User;
|
||||
typedef struct uirc_message {
|
||||
struct uirc_tags {
|
||||
/* See https://ircv3.net/registry#tags for more information */
|
||||
IRC_Tag account;
|
||||
IRC_Tag batch;
|
||||
IRC_Tag label;
|
||||
IRC_Tag msgid;
|
||||
IRC_Tag multiline_concat;
|
||||
IRC_Tag time;
|
||||
IRC_Tag typing;
|
||||
IRC_Tag react;
|
||||
IRC_Tag reply;
|
||||
} tags;
|
||||
IRC_User name;
|
||||
signed short cmd;
|
||||
const char* args[15]; /* 0-13 + NULL */
|
||||
const char* trailing;
|
||||
} IRC_Message;
|
||||
#endif
|
267
include/uirc.h
267
include/uirc.h
|
@ -16,274 +16,13 @@
|
|||
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include "structs.h"
|
||||
#include "mappings.h"
|
||||
#include "helpers.h"
|
||||
#ifndef UIRC_INCLUDED
|
||||
#define UIRC_INCLUDED
|
||||
|
||||
#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
|
||||
|
||||
/* Mode bitmask values */
|
||||
#define MBMASK_WALLOPS 2 /* 010 */
|
||||
#define MBMASK_INVIS 4 /* 100 */
|
||||
|
||||
typedef struct uirc_tag {
|
||||
const char* value;
|
||||
bool clientbound;
|
||||
bool present;
|
||||
} IRC_Tag;
|
||||
typedef struct name {
|
||||
const char* nick;
|
||||
const char* user;
|
||||
const char* host;
|
||||
const char* realname;
|
||||
} IRC_User;
|
||||
typedef struct uirc_message {
|
||||
struct uirc_tags {
|
||||
/* See https://ircv3.net/registry#tags for more information */
|
||||
IRC_Tag account;
|
||||
IRC_Tag batch;
|
||||
IRC_Tag label;
|
||||
IRC_Tag msgid;
|
||||
IRC_Tag multiline_concat;
|
||||
IRC_Tag time;
|
||||
IRC_Tag typing;
|
||||
IRC_Tag react;
|
||||
IRC_Tag reply;
|
||||
} tags;
|
||||
IRC_User name;
|
||||
signed short cmd;
|
||||
const char* args[15]; /* 0-13 + NULL */
|
||||
const char* trailing;
|
||||
} IRC_Message;
|
||||
|
||||
extern const char* const uirc_ircmd[];
|
||||
extern int uirc_tokenize_message(IRC_Message* irc_msg, char** line);
|
||||
extern int uirc_assm_mesg(char* buf, IRC_Message* mesg);
|
||||
extern unsigned int uirc_ircmd_stoi(char* str);
|
||||
|
||||
/* Here begin the helper functions */
|
||||
#ifdef UIRC_HELPERS
|
||||
extern IRC_Message* Assemble_NICK(char* nick);
|
||||
extern IRC_Message* Assemble_USER(char* user, char* realname, int modes);
|
||||
extern IRC_Message* Assemble_PASS(char* password);
|
||||
extern IRC_Message* Assemble_OPER(char* name, char* password);
|
||||
extern IRC_Message* Assemble_MODE(char* nick, char* modes, char* modeparams);
|
||||
extern IRC_Message* Assemble_SERVICE(char* nickname, char* distribution, char* type, char* info);
|
||||
extern IRC_Message* Assemble_QUIT(char* mesg, IRC_User* user);
|
||||
extern IRC_Message* Assemble_SQUIT(char* server, char* comment, IRC_User* user);
|
||||
extern IRC_Message* Assemble_JOIN(char* channels, char* keys, IRC_User* user);
|
||||
extern IRC_Message* Assemble_PART(char* channel, char* message, IRC_User* user);
|
||||
extern IRC_Message* Assemble_TOPIC(char* channel, char* topic, IRC_User* user);
|
||||
extern IRC_Message* Assemble_NAMES(char* channels, char* target);
|
||||
extern IRC_Message* Assemble_LIST(char* channels, char* target);
|
||||
extern IRC_Message* Assemble_INVITE(char* nick, char* channel, IRC_User* user);
|
||||
extern IRC_Message* Assemble_KICK(char* channels, char* users, char* comment, IRC_User* user);
|
||||
extern IRC_Message* Assemble_PRIVMSG(char* target, char* message, IRC_User* source);
|
||||
extern IRC_Message* Assemble_NOTICE(char* target, char* text, IRC_User* user);
|
||||
extern IRC_Message* Assemble_MOTD(char* target);
|
||||
extern IRC_Message* Assemble_LUSERS(char* mask, char* target);
|
||||
extern IRC_Message* Assemble_VERSION(char* target);
|
||||
extern IRC_Message* Assemble_STATS(char* query, char* target);
|
||||
extern IRC_Message* Assemble_LINKS(char* remoteserv, char* servmask);
|
||||
extern IRC_Message* Assemble_TIME(char* target);
|
||||
extern IRC_Message* Assemble_CONNECT(char* target, char* port, char* remote);
|
||||
extern IRC_Message* Assemble_TRACE(char* target);
|
||||
extern IRC_Message* Assemble_ADMIN(char* target);
|
||||
extern IRC_Message* Assemble_INFO(char* target);
|
||||
extern IRC_Message* Assemble_SERVLIST(char* mask, char* type);
|
||||
extern IRC_Message* Assemble_SQUERY(char* servicename, char* text);
|
||||
extern IRC_Message* Assemble_WHO(char* mask, bool oper);
|
||||
extern IRC_Message* Assemble_WHOIS(char* target, char* mask);
|
||||
extern IRC_Message* Assemble_WHOWAS(char* nick, char* count, char* target);
|
||||
extern IRC_Message* Assemble_KILL(char* nick, char* comment);
|
||||
extern IRC_Message* Assemble_PING(char* source, char* target);
|
||||
extern IRC_Message* Assemble_PONG(char* source, char* target);
|
||||
extern IRC_Message* Assemble_ERROR(char* message);
|
||||
extern IRC_Message* Assemble_AWAY(char* mesg);
|
||||
extern IRC_Message* Assemble_REHASH(void);
|
||||
extern IRC_Message* Assemble_DIE(void);
|
||||
extern IRC_Message* Assemble_RESTART(void);
|
||||
extern IRC_Message* Assemble_SUMMON(char* user, char* target, char* channel);
|
||||
extern IRC_Message* Assemble_USERS(char* target);
|
||||
extern IRC_Message* Assemble_WALLOPS(char* text, IRC_User* source);
|
||||
extern IRC_Message* Assemble_USERHOST(char* users[], IRC_User* source);
|
||||
extern IRC_Message* Assemble_ISON(char* users[]);
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PASS = 10,
|
||||
NICK,
|
||||
USER,
|
||||
SERVER,
|
||||
OPER,
|
||||
SERVICE,
|
||||
QUIT,
|
||||
SQUIT,
|
||||
JOIN,
|
||||
PART,
|
||||
MODE,
|
||||
TOPIC,
|
||||
NAMES,
|
||||
LIST,
|
||||
INVITE,
|
||||
KICK,
|
||||
VERSION,
|
||||
STATS,
|
||||
LINKS,
|
||||
TIME,
|
||||
CONNECT,
|
||||
TRACE,
|
||||
ADMIN,
|
||||
INFO,
|
||||
SERVLIST,
|
||||
SQUERY,
|
||||
PRIVMSG,
|
||||
NOTICE,
|
||||
MOTD,
|
||||
LUSERS,
|
||||
WHO,
|
||||
WHOIS,
|
||||
WHOWAS,
|
||||
KILL,
|
||||
PING,
|
||||
PONG,
|
||||
ERROR,
|
||||
AWAY,
|
||||
REHASH,
|
||||
DIE,
|
||||
RESTART,
|
||||
SUMMON,
|
||||
USERS,
|
||||
WALLOPS,
|
||||
USERHOST,
|
||||
ISON
|
||||
};
|
||||
enum {
|
||||
RPL_WELCOME = 1,
|
||||
RPL_YOURHOST = 2,
|
||||
RPL_CREATED = 3,
|
||||
RPL_MYINFO = 4,
|
||||
RPL_BOUNCE = 5,
|
||||
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
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,465 @@
|
|||
#include "../include/uirc.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
static IRC_Message imassm_mesg;
|
||||
const char* RESERVED = "*";
|
||||
void clear_assm(void)
|
||||
{
|
||||
memset((void*)&imassm_mesg, '\0', sizeof(IRC_Message));
|
||||
}
|
||||
IRC_Message* Assemble_NICK(char* nick)
|
||||
{
|
||||
if (nick == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.cmd = NICK;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_USER(char* user, char* realname, int modes)
|
||||
{
|
||||
if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS))
|
||||
return NULL;
|
||||
clear_assm();
|
||||
char local_mode[2];
|
||||
sprintf(local_mode, "%i", modes);
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = local_mode;
|
||||
imassm_mesg.args[2] = RESERVED;
|
||||
imassm_mesg.trailing = realname;
|
||||
imassm_mesg.cmd = USER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PASS(char* password)
|
||||
{
|
||||
if (password == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = password;
|
||||
imassm_mesg.cmd = PASS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_OPER(char* name, char* password)
|
||||
{
|
||||
if (name == NULL || password == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = name;
|
||||
imassm_mesg.args[1] = password;
|
||||
imassm_mesg.cmd = OPER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_MODE(char* nick, char* modes, char* modeparams) /* TODO: Write a mode string creator */
|
||||
{
|
||||
if (nick == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = modes;
|
||||
imassm_mesg.args[2] = modeparams;
|
||||
imassm_mesg.cmd = MODE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SERVICE(char* nickname, char* distribution, char* type, char* info)
|
||||
{
|
||||
if (nickname == NULL || distribution == NULL || type == NULL || info == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nickname;
|
||||
imassm_mesg.args[1] = RESERVED;
|
||||
imassm_mesg.args[2] = distribution;
|
||||
imassm_mesg.args[3] = "0";
|
||||
imassm_mesg.args[4] = RESERVED;
|
||||
imassm_mesg.trailing = info;
|
||||
imassm_mesg.cmd = SERVICE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_QUIT(char* mesg, IRC_User* user)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = mesg;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = QUIT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SQUIT(char* server, char* comment, IRC_User* user)
|
||||
{
|
||||
if (server == NULL || comment == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = server;
|
||||
imassm_mesg.trailing = comment;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = SQUIT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_JOIN(char* channels, char* keys, IRC_User* user)
|
||||
{
|
||||
if (channels == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = keys;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = JOIN;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PART(char* channel, char* message, IRC_User* user)
|
||||
{
|
||||
if (channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channel;
|
||||
imassm_mesg.trailing = message;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = PART;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
/* 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
|
||||
*/
|
||||
IRC_Message* Assemble_TOPIC(char* channel, char* topic, IRC_User* user)
|
||||
{
|
||||
if (channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channel;
|
||||
imassm_mesg.trailing = topic;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = TOPIC;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_NAMES(char* channels, char* target)
|
||||
{
|
||||
if (channels == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = NAMES;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_LIST(char* channels, char* target)
|
||||
{
|
||||
if (channels == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = LIST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_INVITE(char* nick, char* channel, IRC_User* user)
|
||||
{
|
||||
if (nick == NULL || channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = channel;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = INVITE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_KICK(char* channels, char* users, char* comment, IRC_User* user)
|
||||
{
|
||||
if (channels == NULL || users == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = users;
|
||||
imassm_mesg.trailing = comment;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = KICK;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PRIVMSG(char* target, char* message, IRC_User* source)
|
||||
{
|
||||
if (target == NULL || message == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.trailing = message;
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = PRIVMSG;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_NOTICE(char* target, char* text, IRC_User* user)
|
||||
{
|
||||
if (target == NULL || text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.args[1] = text;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = NOTICE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_MOTD(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = MOTD;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_LUSERS(char* mask, char* target)
|
||||
{
|
||||
if (mask == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = LUSERS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_VERSION(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = VERSION;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_STATS(char* query, char* target)
|
||||
{
|
||||
if (query == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = query;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = STATS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_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* Assemble_TIME(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = TIME;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_CONNECT(char* target, char* port, char* remote)
|
||||
{
|
||||
if (target == NULL || port == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.args[1] = port;
|
||||
imassm_mesg.args[2] = remote;
|
||||
imassm_mesg.cmd = CONNECT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_TRACE(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = TRACE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_ADMIN(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = ADMIN;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_INFO(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = INFO;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SERVLIST(char* mask, char* type)
|
||||
{
|
||||
if (type != NULL && mask == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = type;
|
||||
imassm_mesg.cmd = SERVLIST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SQUERY(char* servicename, char* text)
|
||||
{
|
||||
if (servicename == NULL || text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = servicename;
|
||||
imassm_mesg.trailing = text;
|
||||
imassm_mesg.cmd = SQUERY;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_WHO(char* mask, bool oper)
|
||||
{
|
||||
static const char* const 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* Assemble_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* Assemble_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;
|
||||
}
|
||||
IRC_Message* Assemble_KILL(char* nick, char* comment)
|
||||
{
|
||||
if (nick == NULL || comment == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.trailing = comment;
|
||||
imassm_mesg.cmd = KILL;
|
||||
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* Assemble_PING(char* source, char* target)
|
||||
{
|
||||
if (source == NULL && target == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = (source != NULL && target != NULL) ? source : (target != NULL) ? target : NULL;
|
||||
imassm_mesg.args[1] = (source != NULL && target != NULL) ? target : NULL;
|
||||
imassm_mesg.trailing = (source != NULL && target == NULL) ? source : NULL;
|
||||
imassm_mesg.cmd = PING;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PONG(char* source, char* target)
|
||||
{
|
||||
if (source == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = source;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = PONG;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_ERROR(char* message)
|
||||
{
|
||||
if (message == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = message;
|
||||
imassm_mesg.cmd = ERROR;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_AWAY(char* mesg)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = mesg;
|
||||
imassm_mesg.cmd = AWAY;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_REHASH(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = REHASH;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_DIE(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = DIE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_RESTART(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = RESTART;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_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* Assemble_USERS(char* target)
|
||||
{
|
||||
if (target == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = USERS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_WALLOPS(char* text, IRC_User* source)
|
||||
{
|
||||
if (text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = text;
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = WALLOPS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_USERHOST(char* users[], IRC_User* source)
|
||||
{
|
||||
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];
|
||||
}
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = USERHOST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
/* NOTE: Limited to 14 nicks per command */
|
||||
IRC_Message* Assemble_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;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef UIRC_HELPERS
|
||||
#define UIRC_HELPERS
|
||||
#endif
|
||||
#include "../include/uirc.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char out[513] = {0};
|
||||
uirc_assm_mesg(out, Assemble_PING(NULL, "ok"));
|
||||
printf("Output: %s\n", out);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
465
src/uirc.c
465
src/uirc.c
|
@ -288,468 +288,3 @@ int tok_prefix(char* prefix, IRC_User* user)
|
|||
return ERR_UIRC_INVALID_FORMAT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define UIRC_HELPERS
|
||||
#ifdef UIRC_HELPERS
|
||||
static IRC_Message imassm_mesg;
|
||||
const char* RESERVED = "*";
|
||||
void clear_assm(void)
|
||||
{
|
||||
memset((void*)&imassm_mesg, '\0', sizeof(IRC_Message));
|
||||
}
|
||||
IRC_Message* Assemble_NICK(char* nick)
|
||||
{
|
||||
if (nick == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.cmd = NICK;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_USER(char* user, char* realname, int modes)
|
||||
{
|
||||
if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS))
|
||||
return NULL;
|
||||
clear_assm();
|
||||
char local_mode[2];
|
||||
sprintf(local_mode, "%i", modes);
|
||||
imassm_mesg.args[0] = user;
|
||||
imassm_mesg.args[1] = local_mode;
|
||||
imassm_mesg.args[2] = RESERVED;
|
||||
imassm_mesg.trailing = realname;
|
||||
imassm_mesg.cmd = USER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PASS(char* password)
|
||||
{
|
||||
if (password == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = password;
|
||||
imassm_mesg.cmd = PASS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_OPER(char* name, char* password)
|
||||
{
|
||||
if (name == NULL || password == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = name;
|
||||
imassm_mesg.args[1] = password;
|
||||
imassm_mesg.cmd = OPER;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_MODE(char* nick, char* modes, char* modeparams) /* TODO: Write a mode string creator */
|
||||
{
|
||||
if (nick == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = modes;
|
||||
imassm_mesg.args[2] = modeparams;
|
||||
imassm_mesg.cmd = MODE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SERVICE(char* nickname, char* distribution, char* type, char* info)
|
||||
{
|
||||
if (nickname == NULL || distribution == NULL || type == NULL || info == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nickname;
|
||||
imassm_mesg.args[1] = RESERVED;
|
||||
imassm_mesg.args[2] = distribution;
|
||||
imassm_mesg.args[3] = "0";
|
||||
imassm_mesg.args[4] = RESERVED;
|
||||
imassm_mesg.trailing = info;
|
||||
imassm_mesg.cmd = SERVICE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_QUIT(char* mesg, IRC_User* user)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = mesg;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = QUIT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SQUIT(char* server, char* comment, IRC_User* user)
|
||||
{
|
||||
if (server == NULL || comment == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = server;
|
||||
imassm_mesg.trailing = comment;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = SQUIT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_JOIN(char* channels, char* keys, IRC_User* user)
|
||||
{
|
||||
if (channels == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = keys;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = JOIN;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PART(char* channel, char* message, IRC_User* user)
|
||||
{
|
||||
if (channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channel;
|
||||
imassm_mesg.trailing = message;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = PART;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
/* 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
|
||||
*/
|
||||
IRC_Message* Assemble_TOPIC(char* channel, char* topic, IRC_User* user)
|
||||
{
|
||||
if (channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channel;
|
||||
imassm_mesg.trailing = topic;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = TOPIC;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_NAMES(char* channels, char* target)
|
||||
{
|
||||
if (channels == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = NAMES;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_LIST(char* channels, char* target)
|
||||
{
|
||||
if (channels == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = LIST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_INVITE(char* nick, char* channel, IRC_User* user)
|
||||
{
|
||||
if (nick == NULL || channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.args[1] = channel;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = INVITE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_KICK(char* channels, char* users, char* comment, IRC_User* user)
|
||||
{
|
||||
if (channels == NULL || users == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = channels;
|
||||
imassm_mesg.args[1] = users;
|
||||
imassm_mesg.trailing = comment;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = KICK;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PRIVMSG(char* target, char* message, IRC_User* source)
|
||||
{
|
||||
if (target == NULL || message == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.trailing = message;
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = PRIVMSG;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_NOTICE(char* target, char* text, IRC_User* user)
|
||||
{
|
||||
if (target == NULL || text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.args[1] = text;
|
||||
if (user != NULL)
|
||||
imassm_mesg.name = *user;
|
||||
imassm_mesg.cmd = NOTICE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_MOTD(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = MOTD;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_LUSERS(char* mask, char* target)
|
||||
{
|
||||
if (mask == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = LUSERS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_VERSION(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = VERSION;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_STATS(char* query, char* target)
|
||||
{
|
||||
if (query == NULL && target != NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = query;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = STATS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_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* Assemble_TIME(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = TIME;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_CONNECT(char* target, char* port, char* remote)
|
||||
{
|
||||
if (target == NULL || port == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.args[1] = port;
|
||||
imassm_mesg.args[2] = remote;
|
||||
imassm_mesg.cmd = CONNECT;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_TRACE(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = TRACE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_ADMIN(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = ADMIN;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_INFO(char* target)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = INFO;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SERVLIST(char* mask, char* type)
|
||||
{
|
||||
if (type != NULL && mask == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = mask;
|
||||
imassm_mesg.args[1] = type;
|
||||
imassm_mesg.cmd = SERVLIST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_SQUERY(char* servicename, char* text)
|
||||
{
|
||||
if (servicename == NULL || text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = servicename;
|
||||
imassm_mesg.trailing = text;
|
||||
imassm_mesg.cmd = SQUERY;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_WHO(char* mask, bool oper)
|
||||
{
|
||||
static const char* const 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* Assemble_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* Assemble_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;
|
||||
}
|
||||
IRC_Message* Assemble_KILL(char* nick, char* comment)
|
||||
{
|
||||
if (nick == NULL || comment == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = nick;
|
||||
imassm_mesg.trailing = comment;
|
||||
imassm_mesg.cmd = KILL;
|
||||
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* Assemble_PING(char* source, char* target)
|
||||
{
|
||||
if (source == NULL && target == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = (source != NULL && target != NULL) ? source : (target != NULL) ? target : NULL;
|
||||
imassm_mesg.args[1] = (source != NULL && target != NULL) ? target : NULL;
|
||||
imassm_mesg.trailing = (source != NULL && target == NULL) ? source : NULL;
|
||||
imassm_mesg.cmd = PING;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_PONG(char* source, char* target)
|
||||
{
|
||||
if (source == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = source;
|
||||
imassm_mesg.args[1] = target;
|
||||
imassm_mesg.cmd = PONG;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_ERROR(char* message)
|
||||
{
|
||||
if (message == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = message;
|
||||
imassm_mesg.cmd = ERROR;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_AWAY(char* mesg)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = mesg;
|
||||
imassm_mesg.cmd = AWAY;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_REHASH(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = REHASH;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_DIE(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = DIE;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_RESTART(void)
|
||||
{
|
||||
clear_assm();
|
||||
imassm_mesg.cmd = RESTART;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_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* Assemble_USERS(char* target)
|
||||
{
|
||||
if (target == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = target;
|
||||
imassm_mesg.cmd = USERS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_WALLOPS(char* text, IRC_User* source)
|
||||
{
|
||||
if (text == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.trailing = text;
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = WALLOPS;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
IRC_Message* Assemble_USERHOST(char* users[], IRC_User* source)
|
||||
{
|
||||
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];
|
||||
}
|
||||
if (source != NULL)
|
||||
imassm_mesg.name = *source;
|
||||
imassm_mesg.cmd = USERHOST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
/* NOTE: Limited to 14 nicks per command */
|
||||
IRC_Message* Assemble_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
|
||||
|
|
Reference in New Issue