diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-06-10 20:35:05 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-06-10 20:35:05 +0100 |
commit | 5d21a0eb5bd7deed931078a302ca3b8d6881e62e (patch) | |
tree | f3990dcb60c579c59d83f136aa65e977d4853bb5 /functions.h | |
parent | 8e629c02b1a12e88110bcda7f0e67c6a74ff9741 (diff) |
Refactoring - move most functions into functions.h/functions.c except connect/exit functions only relevant in main.c.
Diffstat (limited to 'functions.h')
-rw-r--r-- | functions.h | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/functions.h b/functions.h index d62194d..cba1d72 100644 --- a/functions.h +++ b/functions.h @@ -32,7 +32,14 @@ #include <stdarg.h> #include <limits.h> -#define MAXDATASIZE 513 // max number of bytes we can get at once (RFC2812 says 512, plus one for null terminator) +#include "sockets.h" +#include "structures.h" +#include "replay.h" + +#define MAXDATASIZE 513 // Maximum number of bytes we can get at once (RFC2812 says 512, plus one for null terminator) +#define MAXCLIENTS 32 // Maximum number of clients that can connect to the bouncer at a time +#define MAXCHANNELS 1024 // Let's assume 1024 is reasonable for now (it's configured per IRCd) +#define MAXRFCNICKLEN 9 // From RFC 1459 // getstdin() return codes #define OK 0 @@ -69,4 +76,72 @@ void updatenickuserhost(char *nickuserhost, char *nick); // Update an existing 001 greeting with a new nickuserhost void updategreetings(char *greeting001, char *greeting002, char *greeting003, char *greeting004, char *greeting005a, char *greeting005b, char *greeting005c, char *newnickuserhost, char *oldnickuserhost, char *newnick, char *oldnick); +// Return index of requested client FD within the clients array. +// TODO - Use this wherever we are calculating the position (various places) instead of +// duplicating code. +int arrindex(struct client *clients, int clientfd); + +// Send whatever string to a specific client by providing the FD +// If "bypass" == 1 then permit sending to client even if unauthenticated (for instance for a CAP LS response) +int sendtoclient(int fd, char *strsrc, struct client *clients, struct settings *settings, int bypass); + +// Relay/send message to all clients (optionally except one) +// "except" is used to send to all clients _except_ the fd provided (except = 0 (EXCEPT_NONE) avoids this, i.e. sends to all) +// "except" is really the "sourcefd" and is also used as part of the authentication check - this is messy and they should perhaps be two separate arguments. +int sendtoallclients(struct client *clients, char *strsrc, int except, struct settings *settings); + +// Send whatever string to the real IRC server +// Client FD and arrays needed to make sure anything relayed from a client is from an authenticated client. +// clientfd of "0" means trusted, used when we are sending things ourselves that weren't relayed +// from a real client. +int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struct client *clients, struct settings *settings); + +// Disconnect the client fd "fd" by close()ing it and remove +// it from the array of clients. +// Also set its authentication and registration statuses to 0. +// Also set the pending statuses to 0 +int disconnectclient(int fd, struct client *clients, struct ircdstrings *ircdstrings, struct settings *settings); + +int createchannel(struct channel *channels, char *name, char *topic, char *topicwho, char *topicwhen); + +int setchanneltopicwhotime(struct channel *channels, char *channelname, char *who, char *when); + +int setchanneltopic(struct channel *channels, char *channelname, char *topic); + +int getchannelcount(struct channel *channels); + +int removechannel(struct channel *channels, char *name); + +// Check if we have the NAMES for the channel 'name' already. +// Return the 1 if we do, 0 if we don't, or -1 if there's an error. +int channelgotnames(struct channel *channels, char *name); + +// Check if we are in a channel named "name" or not. +// Return 1 if we are, or 0 if not. +int inchannel(struct channel *channels, char *name); + +// Returns the array index in the 'channels' array of the channel +// named 'channel'. +// Returns -1 if there was an error. +int channelindex(struct channel *channels, char *name); + +// Send the requested number of lines of replay log to the requested client +// 'sourcefd' is the client to send to, and replayseconds is the number of +// seconds of replay to replay. +// Returns 1 for success or 0 for failure. +int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstrings *ircdstrings, struct channel *channels); + +// Return a count of the number of connected clients +int numclients(struct client *clients); + +// Join any channels that were configured to be automatically +// joined in the configuration file. +// Returns 1 on success or 0 on failure. +int joinautochannels(SSL *server_ssl, struct client *clients, struct settings *settings); + +// Try to make a new nick if no configured are available or liked by the server +// Do this by sticking a number on the end of the current nick and trying numbers +// 1 through to 9. +void tryautonick(struct ircdstrings *ircdstrings); + #endif |