split IRC.c and moved it to a different repo
This commit is contained in:
9
include/IRC/IRC.h
Normal file
9
include/IRC/IRC.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef IRC_H
|
||||
#define IRC_H
|
||||
|
||||
#include "IRC/IRC_structs.h"
|
||||
#include "IRC/IRC_events.h"
|
||||
#include "IRC/IRC_numerics.h"
|
||||
#include "IRC/IRC_functions.h"
|
||||
|
||||
#endif
|
||||
16
include/IRC/IRC_events.h
Normal file
16
include/IRC/IRC_events.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef IRC_EVENTS_H
|
||||
#define IRC_EVENTS_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IRC_EVENT_PRIVMSG,
|
||||
IRC_EVENT_NOTICE,
|
||||
IRC_EVENT_JOIN,
|
||||
IRC_EVENT_PART,
|
||||
IRC_EVENT_QUIT,
|
||||
IRC_EVENT_MODESET,
|
||||
IRC_EVENT_AWAY,
|
||||
IRC_EVENT_KICK
|
||||
} irc_event_type_t;
|
||||
|
||||
#endif
|
||||
49
include/IRC/IRC_functions.h
Normal file
49
include/IRC/IRC_functions.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef IRC_FUNCTIONS_H
|
||||
#define IRC_FUNCTIONS_H
|
||||
|
||||
#include "IRC_structs.h"
|
||||
#include "defines.h"
|
||||
|
||||
PUBLIC void IRC_ParseMessage(char* line, irc_message_t *msg);
|
||||
PUBLIC void IRC_ProcessMessage(irc_message_t *msg, irc_client_t *irc);
|
||||
|
||||
// various IRC commands
|
||||
PUBLIC void IRC_PRIVMSG(char* to, char* msg, irc_client_t *irc);
|
||||
PUBLIC void IRC_NOTICE(char* to, char* msg, irc_client_t *irc);
|
||||
PUBLIC void IRC_NICK(char *nick, irc_client_t *irc);
|
||||
PUBLIC void IRC_USER(char *ident, char* realname, irc_client_t *irc);
|
||||
|
||||
PUBLIC void IRC_CTCPSend(char *to, char *cmd, irc_client_t *irc);
|
||||
|
||||
// registration
|
||||
PUBLIC void IRC_SetConnectionParameters(char* host, int port, irc_connection_type_t conntype, irc_client_t *irc);
|
||||
PUBLIC void IRC_SetIdentityParameters(char* nickname, char* username, char* realname, irc_client_t *irc);
|
||||
PUBLIC void IRC_Register(irc_client_t *irc);
|
||||
PUBLIC void IRC_SetSASLParameters(irc_sasl_mechanism_t, char* username, char* password, irc_client_t *irc);
|
||||
|
||||
PUBLIC void IRC_RequestSASLAuthentication(irc_client_t *irc);
|
||||
|
||||
// Capability negotiation block
|
||||
PUBLIC void IRC_StartCapabilityNegotiation(irc_client_t *irc);
|
||||
PUBLIC void IRC_RequestCapabilities(char* caps, irc_client_t *irc);
|
||||
PUBLIC void IRC_EndCapabilityNegotiation(irc_client_t *irc);
|
||||
|
||||
PUBLIC void IRC_NeedCapabilities(char* caps, irc_client_t *irc);
|
||||
|
||||
PUBLIC int IRC_ParseCapabilities(char* caps, irc_capability_t *capabilities, int capsLength);
|
||||
|
||||
// raw socket things
|
||||
PUBLIC void IRC_Connect(irc_client_t *irc);
|
||||
PUBLIC ssize_t IRC_Receive(irc_client_t *irc, char* toBuf, size_t bufSize);
|
||||
PUBLIC void IRC_Send(irc_client_t *irc, char* toSend);
|
||||
PUBLIC void IRC_Close(irc_client_t *irc);
|
||||
|
||||
// init
|
||||
PUBLIC int IRC_Init(irc_client_t *irc);
|
||||
PUBLIC void IRC_Free(irc_client_t *irc);
|
||||
|
||||
PUBLIC int IRC_PollEvent(irc_event_t *event, irc_client_t *irc);
|
||||
|
||||
void IRC_PushEvent(irc_event_t *event, irc_client_t *irc);
|
||||
|
||||
#endif
|
||||
203
include/IRC/IRC_numerics.h
Normal file
203
include/IRC/IRC_numerics.h
Normal file
@@ -0,0 +1,203 @@
|
||||
#ifndef IRC_NUMERICS_H
|
||||
#define IRC_NUMERICS_H
|
||||
|
||||
// * 0xx (initial login information)
|
||||
#define RPL_WELCOME "001"
|
||||
#define RPL_YOURHOST "002"
|
||||
#define RPL_CREATED "003"
|
||||
#define RPL_MYINFO "004"
|
||||
#define RPL_ISUPPORT "005"
|
||||
#define RPL_BOUNCE "010" /* deprecated */
|
||||
|
||||
// * 2xx (request information)
|
||||
|
||||
/* replies to STATS */
|
||||
#define RPL_STATSCOMMANDS "212"
|
||||
#define RPL_ENDOFSTATS "219"
|
||||
#define RPL_STATSUPTIME "242"
|
||||
|
||||
/* server user modes on-connect */
|
||||
#define RPL_UMODEIS "221"
|
||||
|
||||
/* replies to LUSERS */
|
||||
#define RPL_LUSERCLIENT "251"
|
||||
#define RPL_LUSEROP "252"
|
||||
#define RPL_LUSERUNKNOWN "253"
|
||||
#define RPL_LUSERCHANNELS "254"
|
||||
#define RPL_LUSERME "255"
|
||||
#define RPL_LOCALUSERS "265"
|
||||
#define RPL_GLOBALUSERS "266"
|
||||
|
||||
/* replies to ADMIN */
|
||||
#define RPL_ADMINME "256"
|
||||
#define RPL_ADMINLOC1 "257"
|
||||
#define RPL_ADMINLOC2 "258"
|
||||
#define RPL_ADMINEMAIL "259"
|
||||
|
||||
/* generic replies (i.e. ratelimiting) */
|
||||
#define RPL_TRYAGAIN "263"
|
||||
|
||||
/* WHOIS info */
|
||||
#define RPL_WHOISCERTFP "276"
|
||||
|
||||
// * 3xx (information for clients)
|
||||
#define RPL_NONE "300"
|
||||
|
||||
/* replies to WHOIS/WHOWAS */
|
||||
#define RPL_AWAY "301"
|
||||
#define RPL_WHOISREGNICK "307"
|
||||
#define RPL_WHOISUSER "311"
|
||||
#define RPL_WHOISSERVER "312"
|
||||
#define RPL_WHOISOPERATOR "313"
|
||||
#define RPL_WHOWASUSER "314"
|
||||
#define RPL_WHOISIDLE "317"
|
||||
#define RPL_WHOISCHANNELS "319"
|
||||
#define RPL_WHOISSPECIAL "320"
|
||||
#define RPL_WHOISACCOUNT "330"
|
||||
#define RPL_WHOISACTUALLY "338"
|
||||
#define RPL_WHOISHOST "378"
|
||||
#define RPL_WHOISMODES "379"
|
||||
#define RPL_ENDOFWHOIS "318"
|
||||
#define RPL_ENDOFWHOWAS "369"
|
||||
#define ERR_WASNOSUCHNICK "406" /* WHOWAS error */
|
||||
#define RPL_WHOISSECURE "671"
|
||||
|
||||
/* replies to WHO */
|
||||
#define RPL_WHOREPLY "352"
|
||||
#define RPL_ENDOFWHO "315"
|
||||
|
||||
/* replies to LIST */
|
||||
#define RPL_LISTSTART "321"
|
||||
#define RPL_LIST "322"
|
||||
#define RPL_LISTEND "323"
|
||||
|
||||
/* upon joining a channel */
|
||||
#define RPL_CHANNELMODEIS "324"
|
||||
#define RPL_CREATIONTIME "329"
|
||||
#define RPL_TOPIC "332"
|
||||
#define RPL_TOPICWHOTIME "333"
|
||||
|
||||
/* replies to TOPIC */
|
||||
#define RPL_NOTOPIC "331"
|
||||
|
||||
/* replies to INVITE */
|
||||
#define RPL_INVITELIST "336"
|
||||
#define RPL_ENDOFINVITELIST "337"
|
||||
#define RPL_INVITING "341"
|
||||
|
||||
/* replies to MODE */
|
||||
#define RPL_INVEXLIST "346"
|
||||
#define RPL_ENDOFINVEXLIST "347"
|
||||
#define RPL_EXCEPTLIST "348"
|
||||
#define RPL_ENDOFEXCEPTLIST "349"
|
||||
#define RPL_BANLIST "367"
|
||||
#define RPL_ENDOFBANLIST "368"
|
||||
#define ERR_INVALIDMODEPARAM "696"
|
||||
|
||||
/* replies to INFO */
|
||||
#define RPL_INFO "371"
|
||||
#define RPL_ENDOFINFO "374"
|
||||
|
||||
/* when sending a Message of the Day */
|
||||
#define RPL_MOTDSTART "375"
|
||||
#define RPL_MOTD "372"
|
||||
#define RPL_ENDOFMOTD "376"
|
||||
|
||||
/* replies to VERSION */
|
||||
#define RPL_VERSION "351"
|
||||
|
||||
/* replies to NAMES */
|
||||
#define RPL_NAMREPLY "353"
|
||||
#define RPL_ENDOFNAMES "366"
|
||||
|
||||
/* replies to LINKS */
|
||||
#define RPL_LINKS "364"
|
||||
#define RPL_ENDOFLINKS "365"
|
||||
|
||||
/* replies to OPER */
|
||||
#define RPL_YOUREOPER "381"
|
||||
|
||||
/* replies to REHASH */
|
||||
#define RPL_REHASHING "382"
|
||||
|
||||
/* replies to TIME */
|
||||
#define RPL_TIME "391"
|
||||
|
||||
/* replies to USERHOST */
|
||||
#define RPL_USERHOST "302"
|
||||
|
||||
/* sent to clients to inform of away status */
|
||||
#define RPL_UNAWAY "305"
|
||||
#define RPL_NOWAWAY "306"
|
||||
|
||||
// * 4xx and 5xx (errors)
|
||||
|
||||
#define ERR_UNKNOWNERROR "400"
|
||||
#define ERR_NOSUCHNICK "401"
|
||||
#define ERR_NOSUCHSERVER "402"
|
||||
#define ERR_NOSUCHCHANNEL "403"
|
||||
#define ERR_CANNOTSENDTOCHAN "404"
|
||||
#define ERR_TOOMANYCHANNELS "405"
|
||||
#define ERR_NOORIGIN "409"
|
||||
#define ERR_NORECIPIENT "411"
|
||||
#define ERR_NOTEXTTOSEND "412"
|
||||
#define ERR_INPUTTOOLONG "417"
|
||||
#define ERR_UNKNOWNCOMMAND "421"
|
||||
#define ERR_NOMOTD "422"
|
||||
#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_NOTREGISTERED "451"
|
||||
#define ERR_NEEDMOREPARAMS "461"
|
||||
#define ERR_ALREADYREGISTERED "462"
|
||||
#define ERR_PASSWDMISMATCH "464"
|
||||
#define ERR_YOUREBANNEDCREEP "465"
|
||||
#define ERR_CHANNELISFULL "471"
|
||||
#define ERR_UNKNOWNMODE "472"
|
||||
#define ERR_INVITEONLYCHAN "473"
|
||||
#define ERR_BANNEDFROMCHAN "474"
|
||||
#define ERR_BADCHANNELKEY "475"
|
||||
#define ERR_BADCHANMASK "476"
|
||||
#define ERR_NOPRIVILEGES "481"
|
||||
#define ERR_CHANOPRIVSNEEDED "482"
|
||||
#define ERR_CANTKILLSERVER "483"
|
||||
#define ERR_NOOPERHOST "491"
|
||||
#define ERR_UMODEUNKNOWNFLAG "501"
|
||||
#define ERR_USERSDONTMATCH "502"
|
||||
#define ERR_INVALIDKEY "525"
|
||||
|
||||
/* replies to HELP */
|
||||
#define ERR_HELPNOTFOUND "524"
|
||||
#define RPL_HELPSTART "704"
|
||||
#define RPL_HELPTXT "705"
|
||||
#define RPL_ENDOFHELP "706"
|
||||
|
||||
// * 6xx (various TLS and IRCv3 stuff)
|
||||
|
||||
/* STARTTLS stuff */
|
||||
#define RPL_STARTTLS "670"
|
||||
#define ERR_STARTTLS "691"
|
||||
|
||||
// * 7xx (various)
|
||||
|
||||
#define ERR_NOPRIVS "723"
|
||||
|
||||
// * 9xx (authentication)
|
||||
|
||||
/* SASL */
|
||||
#define RPL_LOGGEDIN "900"
|
||||
#define RPL_LOGGEDOUT "901"
|
||||
#define RPL_SASLSUCCESS "903"
|
||||
#define ERR_NICKLOCKED "902"
|
||||
#define ERR_SASLFAIL "904"
|
||||
#define ERR_SASLTOOLONG "905"
|
||||
#define ERR_SASLABORTED "906"
|
||||
#define ERR_SASLALREADY "907"
|
||||
#define RPL_SASLMECHS "908"
|
||||
|
||||
|
||||
#endif
|
||||
123
include/IRC/IRC_structs.h
Normal file
123
include/IRC/IRC_structs.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef IRC_STRUCTS_H
|
||||
#define IRC_STRUCTS_H
|
||||
|
||||
#include "IRC/IRC_events.h"
|
||||
#include "netcode.h"
|
||||
#include <stdbool.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SASL_MECHANISM_NONE,
|
||||
SASL_MECHANISM_PLAIN,
|
||||
SASL_MECHANISM_EXTERNAL
|
||||
} irc_sasl_mechanism_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nickname[32];
|
||||
char ident[16];
|
||||
char hostname;
|
||||
} irc_hostmask_t;
|
||||
|
||||
typedef struct {
|
||||
char line[513];
|
||||
char *source;
|
||||
char *command;
|
||||
char *argv[16];
|
||||
int argc;
|
||||
} irc_message_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_event_type_t type;
|
||||
irc_message_t orig_msg;
|
||||
} irc_event_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_hostmask_t hostmask;
|
||||
char prefix;
|
||||
} irc_chanuser_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[64];
|
||||
char topic[513];
|
||||
irc_chanuser_t* users;
|
||||
} irc_channel_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char capLine[96]; // A place for name and args to point to.
|
||||
char *name;
|
||||
char *args;
|
||||
} irc_capability_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char username[32];
|
||||
char password[64];
|
||||
} irc_sasl_plain_credentials_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nickname[32];
|
||||
unsigned char fingerprint[20];
|
||||
} irc_sasl_external_credentials_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_sasl_mechanism_t mechanism;
|
||||
union {
|
||||
irc_sasl_plain_credentials_t plain_credentials;
|
||||
irc_sasl_external_credentials_t external_credentials;
|
||||
};
|
||||
} irc_auth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char nick[32];
|
||||
char altnick[32];
|
||||
char altnick2[32];
|
||||
char username[16];
|
||||
char realname[128];
|
||||
} irc_identity_t;
|
||||
typedef enum
|
||||
{
|
||||
IRC_CONNECTION_PLAINTEXT,
|
||||
IRC_CONNECTION_TLS
|
||||
} irc_connection_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char host[128];
|
||||
int port;
|
||||
irc_connection_type_t connType;
|
||||
} irc_connection_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irc_connection_info_t connectionInfo;
|
||||
sslSockfd_t connection;
|
||||
irc_hostmask_t ownHostmask;
|
||||
char supportedCapabilities[513];
|
||||
char requestedCapabilities[513];
|
||||
irc_capability_t acked[16];
|
||||
|
||||
/* Authentication parameters */
|
||||
irc_auth_t saslAuth;
|
||||
|
||||
/* Identity */
|
||||
irc_identity_t identity;
|
||||
|
||||
irc_event_t* eventQueue; // lives on the heap
|
||||
int eventQueuePtr;
|
||||
} irc_client_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void (*handler)(irc_message_t *msg, irc_client_t *irc);
|
||||
} command_t;
|
||||
|
||||
#endif
|
||||
9
include/IRC/base64.h
Normal file
9
include/IRC/base64.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef BASE64_H
|
||||
#define BASE64_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int base64_encode(const uint8_t *in, size_t in_len, char *out, size_t out_size);
|
||||
|
||||
#endif
|
||||
7
include/IRC/defines.h
Normal file
7
include/IRC/defines.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef DEFINES_H
|
||||
#define DEFINES_H
|
||||
|
||||
#define NUL '\0'
|
||||
#define PUBLIC __attribute__((visibility("default")))
|
||||
|
||||
#endif
|
||||
24
include/IRC/netcode.h
Normal file
24
include/IRC/netcode.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef NETCODE_H
|
||||
#define NETCODE_H
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SSL *ssl;
|
||||
int sockfd;
|
||||
SSL_CTX *ctx;
|
||||
} sslSockfd_t;
|
||||
|
||||
// Returns a socket file descriptor.
|
||||
sslSockfd_t NET_Connect(const char* host, int port);
|
||||
void NET_Send(sslSockfd_t info, const char* toSend);
|
||||
void NET_Close(sslSockfd_t info);
|
||||
|
||||
// TLS versions of the same thing
|
||||
sslSockfd_t NET_TLS_Connect(const char* host, int port);
|
||||
void NET_TLS_Send(sslSockfd_t info, const char* toSend);
|
||||
void NET_TLS_Close(sslSockfd_t info);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user