Add missing commands and finish the functions
This commit is contained in:
parent
373c6476d1
commit
d998c1221a
|
@ -59,7 +59,7 @@ typedef struct uirc_message {
|
|||
const char* trailing;
|
||||
} IRC_Message;
|
||||
|
||||
extern const char* uirc_ircmd[];
|
||||
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);
|
||||
|
@ -79,6 +79,38 @@ 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 {
|
||||
|
@ -106,8 +138,12 @@ enum {
|
|||
TRACE,
|
||||
ADMIN,
|
||||
INFO,
|
||||
SERVLIST,
|
||||
SQUERY,
|
||||
PRIVMSG,
|
||||
NOTICE,
|
||||
MOTD,
|
||||
LUSERS,
|
||||
WHO,
|
||||
WHOIS,
|
||||
WHOWAS,
|
||||
|
@ -117,6 +153,7 @@ enum {
|
|||
ERROR,
|
||||
AWAY,
|
||||
REHASH,
|
||||
DIE,
|
||||
RESTART,
|
||||
SUMMON,
|
||||
USERS,
|
||||
|
|
317
src/uirc.c
317
src/uirc.c
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
#include "uirc.h"
|
||||
|
||||
const char* uirc_ircmd[] = {
|
||||
const char* const uirc_ircmd[] = {
|
||||
[PASS] = "PASS",
|
||||
[NICK] = "NICK",
|
||||
[USER] = "USER",
|
||||
|
@ -42,8 +42,12 @@ const char* uirc_ircmd[] = {
|
|||
[TRACE] = "TRACE",
|
||||
[ADMIN] = "ADMIN",
|
||||
[INFO] = "INFO",
|
||||
[SERVLIST] = "SERVLIST",
|
||||
[SQUERY] = "SQUERY",
|
||||
[PRIVMSG] = "PRIVMSG",
|
||||
[NOTICE] = "NOTICE",
|
||||
[MOTD] = "MOTD",
|
||||
[LUSERS] = "LUSERS",
|
||||
[WHO] = "WHO",
|
||||
[WHOIS] = "WHOIS",
|
||||
[WHOWAS] = "WHOWAS",
|
||||
|
@ -53,6 +57,7 @@ const char* uirc_ircmd[] = {
|
|||
[ERROR] = "ERROR",
|
||||
[AWAY] = "AWAY",
|
||||
[REHASH] = "REHASH",
|
||||
[DIE] = "DIE",
|
||||
[RESTART] = "RESTART",
|
||||
[SUMMON] = "SUMMON",
|
||||
[USERS] = "USERS",
|
||||
|
@ -284,6 +289,7 @@ int tok_prefix(char* prefix, IRC_User* user)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define UIRC_HELPERS
|
||||
#ifdef UIRC_HELPERS
|
||||
static IRC_Message imassm_mesg;
|
||||
const char* RESERVED = "*";
|
||||
|
@ -438,15 +444,312 @@ IRC_Message* Assemble_LIST(char* channels, char* target)
|
|||
imassm_mesg.cmd = LIST;
|
||||
return &imassm_mesg;
|
||||
}
|
||||
/*
|
||||
IRC_Message* Assemble_()
|
||||
IRC_Message* Assemble_INVITE(char* nick, char* channel, IRC_User* user)
|
||||
{
|
||||
if (== NULL)
|
||||
if (nick == NULL || channel == NULL)
|
||||
return NULL;
|
||||
clear_assm();
|
||||
imassm_mesg.args[0] = ;
|
||||
imassm_mesg.cmd = ;
|
||||
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