summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blabouncer.c130
-rw-r--r--functions.c50
-rw-r--r--functions.h8
-rw-r--r--message.c244
-rw-r--r--message.h4
-rw-r--r--structures.h5
6 files changed, 220 insertions, 221 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 4986551..469eb68 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -85,7 +85,7 @@ void sighandler(int sig) {
signum = sig;
}
-int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd, struct ircdstrings *ircdstrings, struct settings *settings, struct client *clients) {
+int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd, struct ircdstate *ircdstate, struct settings *settings, struct client *clients) {
char outgoingmsg[MAXDATASIZE]; // String to send to server
if (settings->servertls) {
@@ -108,31 +108,31 @@ int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd,
// <=============================================
// Initialise IRC connecting/registration state
- // Set ircdstrings to zero-length strings for now
- ircdstrings->greeting001[0] = '\0';
- ircdstrings->greeting002[0] = '\0';
- ircdstrings->greeting003[0] = '\0';
- ircdstrings->greeting004[0] = '\0';
- ircdstrings->greeting005a[0] = '\0';
- ircdstrings->greeting005b[0] = '\0';
- ircdstrings->greeting005c[0] = '\0';
- ircdstrings->ircdname[0] = '\0';
- ircdstrings->nickuserhost[0] = '\0';
- ircdstrings->ircnick[0] = '\0';
- ircdstrings->ircusername[0] = '\0';
- ircdstrings->currentmsg[0] = '\0';
- ircdstrings->mode[0] = '\0';
- // ircdstrings->oldnick is not set here as we want to track reconnections separately
- // And set non-string things to zero (TODO - Rename this from ircdstrings since it's not all strings any more)
- ircdstrings->capmultiprefix = 0;
- ircdstrings->autonicknum = 0;
- ircdstrings->lastmessagetime = time(NULL);
- ircdstrings->timeoutcheck = 0;
- // ircdstrings.reconnecting is not set here as we want to track reconnections separately
+ // Set ircdstate to zero-length strings for now
+ ircdstate->greeting001[0] = '\0';
+ ircdstate->greeting002[0] = '\0';
+ ircdstate->greeting003[0] = '\0';
+ ircdstate->greeting004[0] = '\0';
+ ircdstate->greeting005a[0] = '\0';
+ ircdstate->greeting005b[0] = '\0';
+ ircdstate->greeting005c[0] = '\0';
+ ircdstate->ircdname[0] = '\0';
+ ircdstate->nickuserhost[0] = '\0';
+ ircdstate->ircnick[0] = '\0';
+ ircdstate->ircusername[0] = '\0';
+ ircdstate->currentmsg[0] = '\0';
+ ircdstate->mode[0] = '\0';
+ // ircdstate->oldnick is not set here as we want to track reconnections separately
+ // And set non-string things to zero
+ ircdstate->capmultiprefix = 0;
+ ircdstate->autonicknum = 0;
+ ircdstate->lastmessagetime = time(NULL);
+ ircdstate->timeoutcheck = 0;
+ // ircdstate.reconnecting is not set here as we want to track reconnections separately
// Populate nick and username from our configuration file for now, real IRCd may change them later (TODO - Is this true of username?)
- strcpy(ircdstrings->ircnick, settings->ircnick);
- strcpy(ircdstrings->ircusername, settings->ircusername);
+ strcpy(ircdstate->ircnick, settings->ircnick);
+ strcpy(ircdstate->ircusername, settings->ircusername);
// Send the server password if one was configured
if (settings->ircserverpassword[0]) {
@@ -142,12 +142,12 @@ int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd,
}
// Send our NICK
- snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstrings->ircnick); // TODO - Check for success (with return code)
+ snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstate->ircnick); // TODO - Check for success (with return code)
// sourcefd = 0 as this is a trusted message
sendtoserver(*server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings);
// Send our USER
- snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", ircdstrings->ircusername, settings->ircrealname); // TODO - Check for success (with return code)
+ snprintf(outgoingmsg, MAXDATASIZE, "USER %s 8 * : %s", ircdstate->ircusername, settings->ircrealname); // TODO - Check for success (with return code)
// TODO - Send a more intelligent/correct USER string
// sourcefd = 0 as this is a trusted message
sendtoserver(*server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings);
@@ -171,7 +171,7 @@ int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd,
// Return 1 if we processed something and expect the caller to not need to do anything more
// Return 0 if we didn't process it and the caller might want to do something
//int processircmessage(int *serversockfd, int *clientsockfd, char *str, int source) {
-int processircmessage(SSL *server_ssl, char *str, int source, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, struct settings *settings) {
+int processircmessage(SSL *server_ssl, char *str, int source, struct client *clients, int sourcefd, struct ircdstate *ircdstate, struct channel *channels, struct settings *settings) {
// Track which space-separated token within this response we're on
int counter = 0;
@@ -201,7 +201,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
switch(source) {
case SOURCE_SERVER: // If message(s) were from the real IRC server
- if (processservermessage(server_ssl, str, clients, sourcefd, ircdstrings, channels, settings, tokens, counter)) {
+ if (processservermessage(server_ssl, str, clients, sourcefd, ircdstate, channels, settings, tokens, counter)) {
// We processed something so return true
free(strcopyPtr);
return 1;
@@ -210,7 +210,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
// Don't return if we got here because this means we didn't process something in processservermessage()
break;
case SOURCE_CLIENT: // If message(s) were from a real IRC client
- if (processclientmessage(server_ssl, str, clients, sourcefd, ircdstrings, channels, settings, tokens, counter)) {
+ if (processclientmessage(server_ssl, str, clients, sourcefd, ircdstate, channels, settings, tokens, counter)) {
// We processed something so return true
free(strcopyPtr);
return 1;
@@ -249,7 +249,7 @@ int processircmessage(SSL *server_ssl, char *str, int source, struct client *cli
//
// Return 0 if something went wrong
// Return 1 if everything OK
-int processrawstring(SSL *server_ssl, char *str, int source, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct channel *channels, struct settings *settings) {
+int processrawstring(SSL *server_ssl, char *str, int source, struct client *clients, int sourcefd, struct ircdstate *ircdstate, struct channel *channels, struct settings *settings) {
// Copy to a temporary string so we still have the original in case it's not processed
char *strcopy = strdup(str);
// Keep track of initial pointer for free()ing later
@@ -279,14 +279,14 @@ int processrawstring(SSL *server_ssl, char *str, int source, struct client *clie
// If there is a previous possibly truncated message still in the holding area, the prepend that to the first message of this new lot
// (Only if source was the server since we always strip \r\n from client messages when recving - TODO - Should we be doing that?
- if (ircdstrings->currentmsg[0] && source == SOURCE_SERVER) {
+ if (ircdstate->currentmsg[0] && source == SOURCE_SERVER) {
// Make a copy since we can't have source and destination the same with snprintf
char *strtmp = strdup(messages[0]);
- debugprint(DEBUG_FULL, "processrawstring(): Previous truncated message detected, combining old '%s' with new '%s'...\n", ircdstrings->currentmsg, strtmp);
- snprintf(messages[0], strlen(ircdstrings->currentmsg) + strlen(strtmp) + 1, "%s%s", ircdstrings->currentmsg, strtmp);
- messages[0][strlen(ircdstrings->currentmsg) + strlen(strtmp)] = '\0'; // Make sure it's null terminated
+ debugprint(DEBUG_FULL, "processrawstring(): Previous truncated message detected, combining old '%s' with new '%s'...\n", ircdstate->currentmsg, strtmp);
+ snprintf(messages[0], strlen(ircdstate->currentmsg) + strlen(strtmp) + 1, "%s%s", ircdstate->currentmsg, strtmp);
+ messages[0][strlen(ircdstate->currentmsg) + strlen(strtmp)] = '\0'; // Make sure it's null terminated
debugprint(DEBUG_FULL, "...into new string '%s' and clearing currentmsg holding area.\n", messages[0]);
- ircdstrings->currentmsg[0] = '\0';
+ ircdstate->currentmsg[0] = '\0';
free(strtmp);
}
@@ -295,20 +295,20 @@ int processrawstring(SSL *server_ssl, char *str, int source, struct client *clie
// (Only if source was the server since we always strip \r\n from client messages when recving - TODO - Should we be doing that?
if ((str[strlen(str)-2] != 13 || str[strlen(str)-1] != 10) && source == SOURCE_SERVER) {
debugprint(DEBUG_FULL, "processrawstring(): Truncated message detected, storing final token '%s' for later.\n", messages[messagecount - 1]);
- strncpy(ircdstrings->currentmsg, messages[messagecount - 1], strlen(messages[messagecount - 1]));
- ircdstrings->currentmsg[strlen(messages[messagecount - 1])] = '\0';
+ strncpy(ircdstate->currentmsg, messages[messagecount - 1], strlen(messages[messagecount - 1]));
+ ircdstate->currentmsg[strlen(messages[messagecount - 1])] = '\0';
// Remove it from the message count so it's not processed time time
messagecount--;
} else {
// Otherwise, clear the holding area
- ircdstrings->currentmsg[0] = '\0';
+ ircdstate->currentmsg[0] = '\0';
}
// Go through each message, figure out what it is and if we're doing anything with it
for (int i = 0; i < messagecount; i++) {
// Copy to a temporary string so we still have the original in case it's not processed
char *messagecopy = strdup(messages[i]);
- if (processircmessage(server_ssl, messagecopy, source, clients, sourcefd, ircdstrings, channels, settings)) {
+ if (processircmessage(server_ssl, messagecopy, source, clients, sourcefd, ircdstate, channels, settings)) {
debugprint(DEBUG_FULL, "Message processed: \"%s\", NULLing...\n", messages[i]);
messages[i][0] = '\0';
}
@@ -386,7 +386,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Struct of various strings from and for the real IRCd (such as the greeting strings, the real IRCd's name,
// our nick!user@host string, our nick, username, real name, etc.)
- struct ircdstrings ircdstrings;
+ struct ircdstate ircdstate;
// Struct of channels we're in
struct channel *channels;
@@ -404,9 +404,9 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
SSL *server_ssl = NULL; // Need to create this either way as referenced later
// Set reconnection things to null/zero for now (not used unless reconnecting to server)
- ircdstrings.oldnick[0] = '\0';
- ircdstrings.reconnecting = 0;
- connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstrings, settings, clients);
+ ircdstate.oldnick[0] = '\0';
+ ircdstate.reconnecting = 0;
+ connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstate, settings, clients);
// OpenSSL context for client side (that clients connect to) (need to create this whether or not using TLS as it is referenced later)
SSL_CTX *ctx;
@@ -461,11 +461,11 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Signal caught, do signal handling
debugprint(DEBUG_CRIT, "signal '%d' happened, exiting!\n", signum);
if (signum == SIGINT) {
- cleanexit(server_ssl, clients, 0, &ircdstrings, settings, "SIGINT received");
+ cleanexit(server_ssl, clients, 0, &ircdstate, settings, "SIGINT received");
} else if (signum == SIGTERM) {
- cleanexit(server_ssl, clients, 0, &ircdstrings, settings, "SIGTERM received");
+ cleanexit(server_ssl, clients, 0, &ircdstate, settings, "SIGTERM received");
} else {
- cleanexit(server_ssl, clients, 0, &ircdstrings, settings, "Unexpected signal received");
+ cleanexit(server_ssl, clients, 0, &ircdstate, settings, "Unexpected signal received");
}
} else {
// Some other error
@@ -480,13 +480,13 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_CRIT, "pselect() timed out.\n", errno);
// SERVERTIMEOUT seconds have expired...
- if (ircdstrings.lastmessagetime < time(NULL) - SERVERTIMEOUT && !FD_ISSET(*serversockfd, &rfds)) {
- if (ircdstrings.timeoutcheck == 0) {
+ if (ircdstate.lastmessagetime < time(NULL) - SERVERTIMEOUT && !FD_ISSET(*serversockfd, &rfds)) {
+ if (ircdstate.timeoutcheck == 0) {
// ...and we haven't tried a PING yet, so let's PING the server to see if things are still working
- debugprint(DEBUG_CRIT, "Server might have timed out after %ld seconds, PINGing it...\n", time(NULL) - ircdstrings.lastmessagetime);
- ircdstrings.timeoutcheck = 1;
+ debugprint(DEBUG_CRIT, "Server might have timed out after %ld seconds, PINGing it...\n", time(NULL) - ircdstate.lastmessagetime);
+ ircdstate.timeoutcheck = 1;
char outgoingmsg[MAXDATASIZE];
- if (!snprintf(outgoingmsg, MAXDATASIZE, "PING %s", ircdstrings.ircdname)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, "PING %s", ircdstate.ircdname)) {
fprintf(stderr, "Error while preparing timeout testing PING message!\n");
debugprint(DEBUG_CRIT, "Error while preparing timeout testing PING message\n");
snprintf(outgoingmsg, MAXDATASIZE, "PING timeouttest");
@@ -495,10 +495,10 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
} else {
// ...and we've already PINGed the server and haven't heard back yet, so let's assume we've timed out
// TODO - Code duplication, make a function and share with socket error code below
- debugprint(DEBUG_CRIT, "Server has timed out (%ld seconds), reconnecting!\n", time(NULL) - ircdstrings.lastmessagetime);
+ debugprint(DEBUG_CRIT, "Server has timed out (%ld seconds), reconnecting!\n", time(NULL) - ircdstate.lastmessagetime);
// Tell all clients if we timed out
char alertmsg[MAXDATASIZE];
- snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Server has timed out (%ld seconds), reconnecting!", ircdstrings.ircnick, time(NULL) - ircdstrings.lastmessagetime);
+ snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Server has timed out (%ld seconds), reconnecting!", ircdstate.ircnick, time(NULL) - ircdstate.lastmessagetime);
sendtoallclients(clients, alertmsg, 0, settings);
if (settings->servertls) {
// Finish up with OpenSSL if using server TLS
@@ -510,10 +510,10 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
*serversockfd = createserversocket(settings->ircserver, settings->ircserverport);
// Set reconnection marker for other functions to know we're reconnecting
- ircdstrings.reconnecting = 1;
+ ircdstate.reconnecting = 1;
// Set oldnick in case we change nick when reconnecting so we can inform existing clients
- strcpy(ircdstrings.oldnick, ircdstrings.ircnick);
- connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstrings, settings, clients);
+ strcpy(ircdstate.oldnick, ircdstate.ircnick);
+ connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstate, settings, clients);
}
// Back to top of loop
continue;
@@ -546,7 +546,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
printf("Server socket had an error (sockread return code %d), reconnecting!\n", servernumbytes);
// Tell all clients if we timed out
char alertmsg[MAXDATASIZE];
- snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Server socket had an error (sockread return code %d), reconnecting!", ircdstrings.ircnick, servernumbytes);
+ snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Server socket had an error (sockread return code %d), reconnecting!", ircdstate.ircnick, servernumbytes);
sendtoallclients(clients, alertmsg, 0, settings);
if (settings->servertls) {
// Finish up with OpenSSL if using server TLS
@@ -558,10 +558,10 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
*serversockfd = createserversocket(settings->ircserver, settings->ircserverport);
// Set reconnection marker for other functions to know we're reconnecting
- ircdstrings.reconnecting = 1;
+ ircdstate.reconnecting = 1;
// Set oldnick in case we change nick when reconnecting so we can inform existing clients
- strcpy(ircdstrings.oldnick, ircdstrings.ircnick);
- connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstrings, settings, clients);
+ strcpy(ircdstate.oldnick, ircdstate.ircnick);
+ connecttoircserver(&serverctx, &server_ssl, serversockfd, &ircdstate, settings, clients);
// Back to top of loop
continue;
@@ -573,7 +573,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Try to process received string (which should contain one or more server responses/commands)
// TODO - What if there were two server respones/commands and only one didn't need relaying?
- if (!processrawstring(server_ssl, serverbuf, SOURCE_SERVER, clients, EXCEPT_NONE, &ircdstrings, channels, settings)) {
+ if (!processrawstring(server_ssl, serverbuf, SOURCE_SERVER, clients, EXCEPT_NONE, &ircdstate, channels, settings)) {
fprintf(stderr, "Error: bouncer-server failed to process raw string.\n");
debugprint(DEBUG_CRIT, "Error: bouncer-server failed to process raw string.\n");
}
@@ -638,7 +638,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
if (numclients(clients) >= MAXCLIENTS) {
fprintf(stderr, "too many clients, disconnecting and skipping loop iteration!\n");
debugprint(DEBUG_CRIT, "too many clients, disconnecting and skipping loop iteration!\n");
- disconnectclient(i, clients, &ircdstrings, settings);
+ disconnectclient(i, clients, &ircdstate, settings);
continue;
}
addrlen = sizeof remoteaddr;
@@ -681,7 +681,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
remoteIP, INET6_ADDRSTRLEN), newfd);
// Alert other clients about the new connection
char alertmsg[MAXDATASIZE];
- if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client connected from %s with fd %d.", ircdstrings.ircnick,
+ if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client connected from %s with fd %d.", ircdstate.ircnick,
inet_ntop(remoteaddr.ss_family, get_in_addr((struct sockaddr*)&remoteaddr), remoteIP, INET6_ADDRSTRLEN), newfd)) {
fprintf(stderr, "Error while preparing new client connection NOTICE!\n");
debugprint(DEBUG_CRIT, "Error while preparing new client connection NOTICE!\n");
@@ -704,7 +704,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
debugprint(DEBUG_CRIT, "bouncer-client: socket error, clientnum bytes '%d', errno '%d'.\n", clientnumbytes, errno);
}
// Disconnect the client
- disconnectclient(i, clients, &ircdstrings, settings);
+ disconnectclient(i, clients, &ircdstate, settings);
FD_CLR(i, &rfds); // remove from master set - TODO is this needed at the moment since we just add everything from *clientsockfd to fdmax to rfds
// TODO - Handle the "remove the client" loop not finding the old fd
debugprint(DEBUG_FULL, "bouncer-client: total client connections: %d\n", numclients(clients));
@@ -720,7 +720,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Try to process received string (which should contain one or more client responses/commands)
// TODO - What if there were two server respones/commands and only one didn't need relaying?
- if (!processrawstring(server_ssl, clientbuf, SOURCE_CLIENT, clients, i, &ircdstrings, channels, settings)) {
+ if (!processrawstring(server_ssl, clientbuf, SOURCE_CLIENT, clients, i, &ircdstate, channels, settings)) {
fprintf(stderr, "Error: bouncer-client failed to process raw string.\n");
debugprint(DEBUG_CRIT, "Error: bouncer-client failed to process raw string.\n");
}
diff --git a/functions.c b/functions.c
index c23366d..93fd52b 100644
--- a/functions.c
+++ b/functions.c
@@ -521,12 +521,12 @@ int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struc
// 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 disconnectclient(int fd, struct client *clients, struct ircdstate *ircdstate, struct settings *settings) {
debugprint(DEBUG_SOME, "disconnectclient(): disconnecting client fd '%d'\n", fd);
// Alert other clients about the disconnection (don't send yet, we haven't removed from the clients array yet)
char alertmsg[MAXDATASIZE];
- if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: client with fd %d has disconnected.", ircdstrings->ircnick, fd)) {
+ if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: client with fd %d has disconnected.", ircdstate->ircnick, fd)) {
fprintf(stderr, "Error while preparing authentication failure NOTICE!\n");
debugprint(DEBUG_CRIT, "Error while preparing authentication failure NOTICE!\n");
alertmsg[0] = '\0';
@@ -738,7 +738,7 @@ int channelindex(struct channel *channels, char *name) {
// '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) {
+int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels) {
char outgoingmsg[MAXDATASIZE];
// Figure out how many lines to replay
@@ -749,13 +749,13 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
debugprint(DEBUG_CRIT, "Error getting number of replay lines.\n");
return 0;
} else if (numlines == 0) {
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :0 replay log lines found in the time requested, nothing to send.", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :0 replay log lines found in the time requested, nothing to send.", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
return 1;
}
// Announce the start
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Starting log replay....", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Starting log replay....", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
// Replay those lines!
@@ -802,7 +802,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
extractnickfromprefix(tokens[0]);
// Check if we're currently in this channel or if the log line is from us
- if (!inchannel(channels, tokens[2] + offset) || strncmp(tokens[0], ircdstrings->ircnick, strlen(tokens[0])) == 0) {
+ if (!inchannel(channels, tokens[2] + offset) || strncmp(tokens[0], ircdstate->ircnick, strlen(tokens[0])) == 0) {
debugprint(DEBUG_FULL, "Not sending '%s' replay line '%s'.\n", tokens[1], outgoingmsg);
free(strcopyPtr);
continue;
@@ -816,7 +816,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
}
// Announce the end
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Log replay complete.", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Log replay complete.", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
return 1;
@@ -888,56 +888,56 @@ int joinautochannels(SSL *server_ssl, struct client *clients, struct settings *s
// 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) {
+void tryautonick(struct ircdstate *ircdstate) {
// Increment the attempts counter
- ircdstrings->autonicknum++;
+ ircdstate->autonicknum++;
- if (ircdstrings->autonicknum == 10) {
+ if (ircdstate->autonicknum == 10) {
// We've already tried 9 nicks and failed, give up
printf("tryautonick(): Tried 9 automatic nicks and the server didn't like any, giving up.\n");
debugprint(DEBUG_CRIT, "tryautonick(): Tried 9 automatic nicks and the server didn't like any, giving up.\n");
exit(1);
}
- int oldlen = strlen(ircdstrings->ircnick);
+ int oldlen = strlen(ircdstate->ircnick);
// If we've already started trying autonick, just replace the last character a the new number
- if (ircdstrings->autonicknum > 1) {
- debugprint(DEBUG_FULL, "tryautonick(): already started autonick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick));
- ircdstrings->ircnick[oldlen - 1] = ircdstrings->autonicknum + '0';
+ if (ircdstate->autonicknum > 1) {
+ debugprint(DEBUG_FULL, "tryautonick(): already started autonick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick));
+ ircdstate->ircnick[oldlen - 1] = ircdstate->autonicknum + '0';
// And null terminate
- ircdstrings->ircnick[oldlen] = '\0';
+ ircdstate->ircnick[oldlen] = '\0';
// If the nick is longer than or equal to the RFC 1459 max nick
// length then try sticking the number at the end
} else if (oldlen >= MAXRFCNICKLEN) {
- debugprint(DEBUG_FULL, "tryautonick(): long old nick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick));
+ debugprint(DEBUG_FULL, "tryautonick(): long old nick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick));
// (+ '0' to make char from int)
- ircdstrings->ircnick[MAXRFCNICKLEN] = ircdstrings->autonicknum + '0';
+ ircdstate->ircnick[MAXRFCNICKLEN] = ircdstate->autonicknum + '0';
// And null terminate
- ircdstrings->ircnick[MAXRFCNICKLEN + 1] = '\0';
+ ircdstate->ircnick[MAXRFCNICKLEN + 1] = '\0';
// Otherwise, just stick it on the end (+ '0' to make char from int)
} else {
- debugprint(DEBUG_FULL, "tryautonick(): short old nick, starting with '%s' length '%ld'.\n", ircdstrings->ircnick, strlen(ircdstrings->ircnick));
- ircdstrings->ircnick[oldlen] = ircdstrings->autonicknum + '0';
+ debugprint(DEBUG_FULL, "tryautonick(): short old nick, starting with '%s' length '%ld'.\n", ircdstate->ircnick, strlen(ircdstate->ircnick));
+ ircdstate->ircnick[oldlen] = ircdstate->autonicknum + '0';
// And null terminate
- ircdstrings->ircnick[oldlen + 1] = '\0';
+ ircdstate->ircnick[oldlen + 1] = '\0';
}
- debugprint(DEBUG_FULL, "tryautonick(): set irdstrings->ircnick to '%s'.\n", ircdstrings->ircnick);
+ debugprint(DEBUG_FULL, "tryautonick(): set irdstrings->ircnick to '%s'.\n", ircdstate->ircnick);
}
// Exit the program cleanly - tell clients, tell the server, then exit(0)
// Optional quit message string "quitmsg"
// "sourcefd" of 0 means the request didn't come from a client
-void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct settings *settings, char *quitmsg) {
+void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstate *ircdstate, struct settings *settings, char *quitmsg) {
char outgoingmsg[MAXDATASIZE];
// Tell clients and debug log
if (sourcefd) {
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request from client with fd '%d', message '%s'.", ircdstrings->ircnick, sourcefd, quitmsg);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request from client with fd '%d', message '%s'.", ircdstate->ircnick, sourcefd, quitmsg);
debugprint(DEBUG_CRIT, "Exiting on request from client with fd '%d', message '%s'.\n", sourcefd, quitmsg);
} else {
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request (not from a client), message '%s'.", ircdstrings->ircnick, quitmsg);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request (not from a client), message '%s'.", ircdstate->ircnick, quitmsg);
debugprint(DEBUG_CRIT, "Exiting on request (not from a client), message '%s'.\n", quitmsg);
}
sendtoallclients(clients, outgoingmsg, EXCEPT_NONE, settings);
diff --git a/functions.h b/functions.h
index 91ce35f..7638b61 100644
--- a/functions.h
+++ b/functions.h
@@ -102,7 +102,7 @@ int sendtoserver(SSL *server_ssl, char *strsrc, int str_len, int clientfd, struc
// 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 disconnectclient(int fd, struct client *clients, struct ircdstate *ircdstate, struct settings *settings);
int createchannel(struct channel *channels, char *name, char *topic, char *topicwho, char *topicwhen);
@@ -131,7 +131,7 @@ int channelindex(struct channel *channels, char *name);
// '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);
+int doreplay(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels);
// Return a count of the number of connected clients
int numclients(struct client *clients);
@@ -144,11 +144,11 @@ int joinautochannels(SSL *server_ssl, struct client *clients, struct settings *s
// 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);
+void tryautonick(struct ircdstate *ircdstate);
// Exit the program cleanly - tell clients, tell the server, then exit(0)
// Optional quit message string "quitmsg"
// "sourcefd" of 0 means the request didn't come from a client
-void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct settings *settings, char *quitmsg);
+void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstate *ircdstate, struct settings *settings, char *quitmsg);
#endif
diff --git a/message.c b/message.c
index b021347..e8879b2 100644
--- a/message.c
+++ b/message.c
@@ -19,12 +19,12 @@
// Process an IRC message that came from the real server.
// Return 1 if we processed it, or 0 if we didn't.
-int processservermessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings,
+int processservermessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstate *ircdstate,
struct channel *channels, struct settings *settings, char tokens[MAXTOKENS][MAXDATASIZE], int counter) {
// Record that we received something from the server for timeout checking purposes
- ircdstrings->lastmessagetime = time(NULL); // snprintf(NULL, 0, "%ld", timenow);
+ ircdstate->lastmessagetime = time(NULL); // snprintf(NULL, 0, "%ld", timenow);
// And we can't be timing out
- ircdstrings->timeoutcheck = 0;
+ ircdstate->timeoutcheck = 0;
// Server PING received? If so, send a PONG back with the next element as the argument.
if (strncmp(tokens[0], "PING", strlen(tokens[0])) == 0) {
@@ -46,46 +46,46 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
// Prefix received? TODO - Care about what the prefix is - what if it's a different server/network/whatever?
if (tokens[0][0] == ':') {
debugprint(DEBUG_FULL, "Prefix found: '%s'! Next token is '%s', length %zd.\n", tokens[0], tokens[1], strlen(tokens[1]));
- // Greetings 001 through to 005, store in ircdstrings array for resending when clients connect
+ // Greetings 001 through to 005, store in ircdstate array for resending when clients connect
// Also store our nick!user@host from greeting 001
// Also store the real IRCd's name from greeting 004
if (strncmp(tokens[1], "001", strlen(tokens[1])) == 0) {
- debugprint(DEBUG_FULL, "Found greeting 001 (%s) (length %zd), storing in ircdstrings struct.\n", str, strlen(str));
- strncpy(ircdstrings->greeting001, str, strlen(str));
+ debugprint(DEBUG_FULL, "Found greeting 001 (%s) (length %zd), storing in ircdstate struct.\n", str, strlen(str));
+ strncpy(ircdstate->greeting001, str, strlen(str));
// Null the end of the string
- ircdstrings->greeting001[strlen(str)] = '\0';
- debugprint(DEBUG_FULL, "Storing our nick!user@host (:%s) from greeting 001 in ircdstrings struct.\n", tokens[counter - 1]);
+ ircdstate->greeting001[strlen(str)] = '\0';
+ debugprint(DEBUG_FULL, "Storing our nick!user@host (:%s) from greeting 001 in ircdstate struct.\n", tokens[counter - 1]);
// Prepend a colon (:) first since everything (so far) needs one
- if (!snprintf(ircdstrings->nickuserhost, MAXDATASIZE, ":%s", tokens[counter - 1])) {
+ if (!snprintf(ircdstate->nickuserhost, MAXDATASIZE, ":%s", tokens[counter - 1])) {
fprintf(stderr, "Error while preparing nickuserhost for storage!\n");
debugprint(DEBUG_CRIT, "Error while preparing nickuserhost for storage!\n");
exit(1);
}
// Null the end of the new string
- ircdstrings->nickuserhost[strlen(tokens[counter - 1]) + 1] = '\0'; // +1 for the inserted colon
- debugprint(DEBUG_FULL, "nickuserhost '%s' stored.\n", ircdstrings->nickuserhost);
+ ircdstate->nickuserhost[strlen(tokens[counter - 1]) + 1] = '\0'; // +1 for the inserted colon
+ debugprint(DEBUG_FULL, "nickuserhost '%s' stored.\n", ircdstate->nickuserhost);
return 1;
} else if (strncmp(tokens[1], "002", strlen(tokens[1])) == 0) {
- debugprint(DEBUG_FULL, "Found greeting 002 (%s), storing in ircdstrings struct.\n", str);
- strncpy(ircdstrings->greeting002, str, strlen(str));
+ debugprint(DEBUG_FULL, "Found greeting 002 (%s), storing in ircdstate struct.\n", str);
+ strncpy(ircdstate->greeting002, str, strlen(str));
// Null the end of the string
- ircdstrings->greeting002[strlen(str)] = '\0';
+ ircdstate->greeting002[strlen(str)] = '\0';
return 1;
} else if (strncmp(tokens[1], "003", strlen(tokens[1])) == 0) {
- debugprint(DEBUG_FULL, "Found greeting 003 (%s), storing in ircdstrings struct.\n", str);
- strncpy(ircdstrings->greeting003, str, strlen(str));
+ debugprint(DEBUG_FULL, "Found greeting 003 (%s), storing in ircdstate struct.\n", str);
+ strncpy(ircdstate->greeting003, str, strlen(str));
// Null the end of the string
- ircdstrings->greeting003[strlen(str)] = '\0';
+ ircdstate->greeting003[strlen(str)] = '\0';
return 1;
} else if (strncmp(tokens[1], "004", strlen(tokens[1])) == 0) {
- debugprint(DEBUG_FULL, "Found greeting 004 (%s), storing in ircdstrings struct.\n", str);
- strncpy(ircdstrings->greeting004, str, strlen(str));
+ debugprint(DEBUG_FULL, "Found greeting 004 (%s), storing in ircdstate struct.\n", str);
+ strncpy(ircdstate->greeting004, str, strlen(str));
// Null the end of the string
- ircdstrings->greeting004[strlen(str)] = '\0';
- debugprint(DEBUG_FULL, "Storing the real IRCd's name (%s) from greeting 004 in ircdstrings struct.\n", tokens[3]);
- strncpy(ircdstrings->ircdname, tokens[3], strlen(tokens[3]));
+ ircdstate->greeting004[strlen(str)] = '\0';
+ debugprint(DEBUG_FULL, "Storing the real IRCd's name (%s) from greeting 004 in ircdstate struct.\n", tokens[3]);
+ strncpy(ircdstate->ircdname, tokens[3], strlen(tokens[3]));
// Null the end of the string
- ircdstrings->ircdname[strlen(tokens[3])] = '\0';
+ ircdstate->ircdname[strlen(tokens[3])] = '\0';
// Receiving greeting 004 means we're now registered
// Request IRCv3 multi-prefix extension so we can more accurately inform new clients about current user prefixes
sendtoserver(server_ssl, "CAP REQ multi-prefix", strlen("CAP REQ multi-prefix"), 0, clients, settings);
@@ -94,12 +94,12 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
sendtoserver(server_ssl, settings->connectcommand, strlen(settings->connectcommand), 0, clients, settings);
}
// If this is a reconnection, JOIN existing channels and catch clients up again
- if (ircdstrings->reconnecting) {
+ if (ircdstate->reconnecting) {
// First tell clients if our nick changed
- if (!strcmp(ircdstrings->ircnick, ircdstrings->oldnick) == 0) {
+ if (!strcmp(ircdstate->ircnick, ircdstate->oldnick) == 0) {
debugprint(DEBUG_SOME, "Telling clients about nick change.\n");
char nickmsg[MAXDATASIZE];
- snprintf(nickmsg, MAXDATASIZE, ":%s NICK :%s", ircdstrings->oldnick, ircdstrings->ircnick);
+ snprintf(nickmsg, MAXDATASIZE, ":%s NICK :%s", ircdstate->oldnick, ircdstate->ircnick);
sendtoallclients(clients, nickmsg, sourcefd, settings);
}
@@ -126,18 +126,18 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
for (int i = 0; i < MAXCLIENTS; i++) {
if (clients[i].fd) {
char alertmsg[MAXDATASIZE];
- if (!doreplay(clients[i].fd, settings->replayseconds, clients, settings, ircdstrings, channels)) {
- snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstrings->ircnick);
+ if (!doreplay(clients[i].fd, settings->replayseconds, clients, settings, ircdstate, channels)) {
+ snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstate->ircnick);
sendtoclient(sourcefd, alertmsg, clients, settings, 0);
}
- snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Reconnection complete.", ircdstrings->ircnick);
+ snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :Reconnection complete.", ircdstate->ircnick);
sendtoclient(clients[i].fd, alertmsg, clients, settings, 0);
}
}
// Reconnection complete
- ircdstrings->oldnick[0] = '\0';
- ircdstrings->reconnecting = 0;
+ ircdstate->oldnick[0] = '\0';
+ ircdstate->reconnecting = 0;
// If it's not, deal with auto channels
} else {
// Join any auto channels set in the configuration file
@@ -145,17 +145,17 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
}
return 1;
} else if (strncmp(tokens[1], "005", strlen(tokens[1])) == 0) {
- debugprint(DEBUG_FULL, "Found greeting 005 (%s), storing in ircdstrings struct.\n", str);
- // Find an empty greeting005 string in ircdstrings and store in there...
- if (!ircdstrings->greeting005a[0]) {
- strncpy(ircdstrings->greeting005a, str, strlen(str));
- ircdstrings->greeting005a[strlen(str)] = '\0';
- } else if (!ircdstrings->greeting005b[0]) {
- strncpy(ircdstrings->greeting005b, str, strlen(str));
- ircdstrings->greeting005b[strlen(str)] = '\0';
- } else if (!ircdstrings->greeting005c[0]) {
- strncpy(ircdstrings->greeting005c, str, strlen(str));
- ircdstrings->greeting005c[strlen(str)] = '\0';
+ debugprint(DEBUG_FULL, "Found greeting 005 (%s), storing in ircdstate struct.\n", str);
+ // Find an empty greeting005 string in ircdstate and store in there...
+ if (!ircdstate->greeting005a[0]) {
+ strncpy(ircdstate->greeting005a, str, strlen(str));
+ ircdstate->greeting005a[strlen(str)] = '\0';
+ } else if (!ircdstate->greeting005b[0]) {
+ strncpy(ircdstate->greeting005b, str, strlen(str));
+ ircdstate->greeting005b[strlen(str)] = '\0';
+ } else if (!ircdstate->greeting005c[0]) {
+ strncpy(ircdstate->greeting005c, str, strlen(str));
+ ircdstate->greeting005c[strlen(str)] = '\0';
} else {
// ...or if they are all fill, discard - TODO - Support more than three greeting005 strings!
debugprint(DEBUG_CRIT, "Already stored three greeting 005 strings, discarding this one.\n");
@@ -176,13 +176,13 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *prefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(prefixcopy);
- if (strncmp(prefixcopy, ircdstrings->ircnick, strlen(tokens[0])) == 0) {
- debugprint(DEBUG_FULL, "Server JOIN: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick);
+ if (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0) {
+ debugprint(DEBUG_FULL, "Server JOIN: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
// TODO - Saner way to initialise this since we don't have the variables yet?
// TODO - Defaulting to type '=' which is "public" since I don't know what else to guess.
createchannel(channels, tokens[2], "TOPIC", "TOPICWHO", "0");
} else {
- debugprint(DEBUG_FULL, "Server JOIN: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick);
+ debugprint(DEBUG_FULL, "Server JOIN: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
}
// And then send to all clients
@@ -212,11 +212,11 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *prefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(prefixcopy);
- if (strncmp(prefixcopy, ircdstrings->ircnick, strlen(tokens[0])) == 0) {
- debugprint(DEBUG_FULL, "Server PART: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick);
+ if (strncmp(prefixcopy, ircdstate->ircnick, strlen(tokens[0])) == 0) {
+ debugprint(DEBUG_FULL, "Server PART: nick is ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
removechannel(channels, tokens[2]);
} else {
- debugprint(DEBUG_FULL, "Server PART: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstrings->ircnick);
+ debugprint(DEBUG_FULL, "Server PART: nick is NOT ours ('%s' vs '%s').\n", prefixcopy, ircdstate->ircnick);
}
// And then send to all clients
@@ -385,25 +385,25 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
char *svrprefixcopy = strdup(tokens[0]);
// Just get the nick for comparison
extractnickfromprefix(svrprefixcopy);
- if (strncmp(ircdstrings->ircnick, svrprefixcopy, strlen(ircdstrings->ircnick)) == 0) {
- debugprint(DEBUG_FULL, "Server NICK: nick is ours ('%s' vs '%s').\n", svrprefixcopy, ircdstrings->ircnick);
+ if (strncmp(ircdstate->ircnick, svrprefixcopy, strlen(ircdstate->ircnick)) == 0) {
+ debugprint(DEBUG_FULL, "Server NICK: nick is ours ('%s' vs '%s').\n", svrprefixcopy, ircdstate->ircnick);
// Make a copy of the old nickuserhost for updategreetings() below
- char *nickuserhostcpy = strdup(ircdstrings->nickuserhost);
+ char *nickuserhostcpy = strdup(ircdstate->nickuserhost);
// Update nickuserhost with the new :nick!user@host
- updatenickuserhost(ircdstrings->nickuserhost, tokens[2]);
- debugprint(DEBUG_FULL, "Updated nickuserhost to '%s'.\n", ircdstrings->nickuserhost);
+ updatenickuserhost(ircdstate->nickuserhost, tokens[2]);
+ debugprint(DEBUG_FULL, "Updated nickuserhost to '%s'.\n", ircdstate->nickuserhost);
// Prepare to update ircnick and greetings strings
// Temporary copy of new nickuserhost
- char *prefixcopy = strdup(ircdstrings->nickuserhost);
+ char *prefixcopy = strdup(ircdstate->nickuserhost);
// Get nick from it
extractnickfromprefix(prefixcopy);
// Update greeting strings for relaying to new clients
- updategreetings(ircdstrings->greeting001, ircdstrings->greeting002, ircdstrings->greeting003, ircdstrings->greeting004,
- ircdstrings->greeting005a, ircdstrings->greeting005b, ircdstrings->greeting005c, ircdstrings->nickuserhost,
- nickuserhostcpy, tokens[2], ircdstrings->ircnick);
+ updategreetings(ircdstate->greeting001, ircdstate->greeting002, ircdstate->greeting003, ircdstate->greeting004,
+ ircdstate->greeting005a, ircdstate->greeting005b, ircdstate->greeting005c, ircdstate->nickuserhost,
+ nickuserhostcpy, tokens[2], ircdstate->ircnick);
// Update our nick
- strcpy(ircdstrings->ircnick, prefixcopy);
- debugprint(DEBUG_FULL, "Updated ircnick to '%s'.\n", ircdstrings->ircnick);
+ strcpy(ircdstate->ircnick, prefixcopy);
+ debugprint(DEBUG_FULL, "Updated ircnick to '%s'.\n", ircdstate->ircnick);
free(nickuserhostcpy);
free(prefixcopy);
}
@@ -424,12 +424,12 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
if (counter == 4) {
// Might be our initial mode (e.g. ":nick MODE nick :+iwz")
char comparison[MAXDATASIZE];
- snprintf(comparison, MAXDATASIZE, ":%s MODE %s :", ircdstrings->ircnick, ircdstrings->ircnick);
+ snprintf(comparison, MAXDATASIZE, ":%s MODE %s :", ircdstate->ircnick, ircdstate->ircnick);
if (strncmp(str, comparison, strlen(comparison)) == 0) {
// Looks like it!
debugprint(DEBUG_FULL, "Our initial MODE found (%s), storing for later.\n", tokens[3]);
- // Store in ircdstrings for when clients connect and relay to current clients.
- strcpy(ircdstrings->mode, tokens[3]);
+ // Store in ircdstate for when clients connect and relay to current clients.
+ strcpy(ircdstate->mode, tokens[3]);
// Relay to all current clients anyway - TODO - Necessary?
sendtoallclients(clients, str, sourcefd, settings);
@@ -623,7 +623,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
// Server 432 (ERR_ERRONEUSNICKNAME) or 433 (ERR_NICKNAMEINUSE) received? See which nick we're on and try another.
// (But only if we're not already registered with the real IRC server.)
- if ((strncmp(tokens[1], "432", strlen(tokens[1])) == 0 || strncmp(tokens[1], "433", strlen(tokens[1])) == 0) && !strlen(ircdstrings->greeting004)) {
+ if ((strncmp(tokens[1], "432", strlen(tokens[1])) == 0 || strncmp(tokens[1], "433", strlen(tokens[1])) == 0) && !strlen(ircdstate->greeting004)) {
debugprint(DEBUG_SOME, "Server 432 (ERR_ERRONEUSNICKNAME) or 433 (ERR_NICKNAMEINUSE) found and it is: %s with length %zd! Trying another nick...\n",
tokens[1], strlen(tokens[1]));
@@ -638,45 +638,45 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
}
// Do we have both a nick2 and a nick3? (And not tried autonick yet.)
- if (nick2[0] && nick3[0] && !ircdstrings->autonicknum) {
+ if (nick2[0] && nick3[0] && !ircdstate->autonicknum) {
// Has nick3 already been tried?
- if (strncmp(ircdstrings->ircnick, nick3, strlen(settings->ircnick)) == 0) {
+ if (strncmp(ircdstate->ircnick, nick3, strlen(settings->ircnick)) == 0) {
// Then try autonick
- tryautonick(ircdstrings);
+ tryautonick(ircdstate);
// Has nick2 already been tried?
- } else if (strncmp(ircdstrings->ircnick, nick2, strlen(settings->ircnick)) == 0) {
+ } else if (strncmp(ircdstate->ircnick, nick2, strlen(settings->ircnick)) == 0) {
// Then try nick3
debugprint(DEBUG_SOME, "Trying nick3, nick2 was already tried.\n");
- strcpy(ircdstrings->ircnick, nick3);
+ strcpy(ircdstate->ircnick, nick3);
// Have neither been tried?
} else {
// Then try nick2
debugprint(DEBUG_SOME, "Trying nick2, nick3 is also configured.\n");
- strcpy(ircdstrings->ircnick, nick2);
+ strcpy(ircdstate->ircnick, nick2);
}
// Do we only have a nick2? (And not tried autonick yet.)
- } else if (nick2[0] && !ircdstrings->autonicknum) {
+ } else if (nick2[0] && !ircdstate->autonicknum) {
// Has it already been tried?
- if (strncmp(ircdstrings->ircnick, nick2, strlen(settings->ircnick)) == 0) {
+ if (strncmp(ircdstate->ircnick, nick2, strlen(settings->ircnick)) == 0) {
// Then try autonick
- tryautonick(ircdstrings);
+ tryautonick(ircdstate);
} else {
// Then try it
debugprint(DEBUG_SOME, "Trying nick2, nick3 is not configured.\n");
- strcpy(ircdstrings->ircnick, nick2);
+ strcpy(ircdstate->ircnick, nick2);
}
// Do we have neither? (Or have already started autonick.)
} else {
// Then try autonick
- tryautonick(ircdstrings);
+ tryautonick(ircdstate);
}
// Set whichever one we settled on in the settings in case we reference settings later
- strcpy(settings->ircnick, ircdstrings->ircnick);
+ strcpy(settings->ircnick, ircdstate->ircnick);
// Try it with the server
char outgoingmsg[MAXDATASIZE];
- snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NICK %s", ircdstate->ircnick);
// sourcefd = 0 as this is a trusted message
sendtoserver(server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings);
@@ -688,10 +688,10 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
debugprint(DEBUG_FULL, "Server CAP found and it is: %s with length %zd! Analysing...\n", tokens[1], strlen(tokens[1]));
// If the server said "CAP <ournick> ACK :multi-prefix" then it must have approved our CAP multi-prefix request
if (counter == 5) {
- if (strncmp(tokens[2], ircdstrings->ircnick, strlen(tokens[2])) == 0 &&
+ if (strncmp(tokens[2], ircdstate->ircnick, strlen(tokens[2])) == 0 &&
strncmp(tokens[3], "ACK", strlen(tokens[3])) == 0 &&
strncmp(tokens[4], ":multi-prefix", strlen(tokens[4])) == 0) {
- ircdstrings->capmultiprefix = 1;
+ ircdstate->capmultiprefix = 1;
}
}
// We didn't handle it
@@ -730,7 +730,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int
// Process an IRC message that came from a client.
// Return 1 if we processed it, or 0 if we didn't.
-int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings,
+int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstate *ircdstate,
struct channel *channels, struct settings *settings, char tokens[MAXTOKENS][MAXDATASIZE], int counter) {
// PASS received? User is trying to log in, check their password.
if (strncasecmp(tokens[0], "PASS", strlen(tokens[0])) == 0) {
@@ -744,7 +744,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
debugprint(DEBUG_FULL, "Found and authenticated fd in arr_authed.\n");
// Alert other clients about the successful authentication
char alertmsg[MAXDATASIZE];
- if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client with fd %d has successfully authenticated.", ircdstrings->ircnick, sourcefd)) {
+ if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client with fd %d has successfully authenticated.", ircdstate->ircnick, sourcefd)) {
fprintf(stderr, "Error while preparing authentication success NOTICE!\n");
debugprint(DEBUG_CRIT, "Error while preparing authentication success NOTICE!\n");
alertmsg[0] = '\0';
@@ -755,10 +755,10 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
}
} else {
debugprint(DEBUG_SOME, "Password rejected, disconnecting fd %d.\n", sourcefd);
- disconnectclient(sourcefd, clients, ircdstrings, settings);
+ disconnectclient(sourcefd, clients, ircdstate, settings);
// Alert other clients about the failed authentication
char alertmsg[MAXDATASIZE];
- if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client with fd %d has failed to authenticate.", ircdstrings->ircnick, sourcefd)) {
+ if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client with fd %d has failed to authenticate.", ircdstate->ircnick, sourcefd)) {
fprintf(stderr, "Error while preparing authentication failure NOTICE!\n");
debugprint(DEBUG_CRIT, "Error while preparing authentication failure NOTICE!\n");
alertmsg[0] = '\0';
@@ -773,7 +773,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// CAP received? Clients can send CAP before PASS so we have to deal with this even if they are not authenticated yet.
if (strncasecmp(tokens[0], "CAP", strlen(tokens[0])) == 0) {
// But only do something if the real server told us it had a CAP (only multi-prefix for now)
- if (ircdstrings->capmultiprefix == 1) {
+ if (ircdstate->capmultiprefix == 1) {
debugprint(DEBUG_FULL, "Client CAP received and the server supports CAPs, continuing.\n");
} else {
debugprint(DEBUG_FULL, "Client CAP received but the server doesn't support CAPs, returning.\n");
@@ -785,7 +785,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
char outgoingmsg[MAXDATASIZE];
// If client is requesting CAP list, send it...
if (strncasecmp(tokens[1], "LS", strlen(tokens[1])) == 0) {
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s CAP * LS :multi-prefix", ircdstrings->ircdname)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s CAP * LS :multi-prefix", ircdstate->ircdname)) {
fprintf(stderr, "Error while preparing CAP LS response!\n");
debugprint(DEBUG_CRIT, "Error while preparing CAP LS response!\n");
outgoingmsg[0] = '\0';
@@ -797,7 +797,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
} else if (strncasecmp(tokens[1], "REQ", strlen(tokens[1])) == 0) {
// ...and it is "multi-prefix", send it
if (strncasecmp(tokens[2], ":multi-prefix", strlen(tokens[2])) == 0) {
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s CAP %s ACK :multi-prefix ", ircdstrings->ircdname, ircdstrings->ircnick)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s CAP %s ACK :multi-prefix ", ircdstate->ircdname, ircdstate->ircnick)) {
fprintf(stderr, "Error while preparing CAP ACK response!\n");
debugprint(DEBUG_CRIT, "Error while preparing CAP ACK response!\n");
outgoingmsg[0] = '\0';
@@ -830,44 +830,44 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
clients[arrindex(clients, sourcefd)].pendingcap = 0;
// Tell the client to go away if we aren't registered with the real server yet as defined by the last greeting not being set yet
- if (!strlen(ircdstrings->greeting004)) {
+ if (!strlen(ircdstate->greeting004)) {
sendtoclient(sourcefd, "Sorry, we aren't registered with a real IRC server yet.", clients, settings, 0);
- disconnectclient(sourcefd, clients, ircdstrings, settings);
+ disconnectclient(sourcefd, clients, ircdstate, settings);
return 1;
}
// Send IRC greeting strings (001/RPL_WELCOME, 002/RPL_YOURHOST, 003/RPL_CREATED, 004/RPL_MYINFO, 005/RPL_ISUPPORT) to client
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting001);
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting001);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting002);
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting002);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting003);
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting003);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting004);
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting004);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- if (ircdstrings->greeting005a[0]) {
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting005a);
+ if (ircdstate->greeting005a[0]) {
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting005a);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
}
- if (ircdstrings->greeting005b[0]) {
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting005b);
+ if (ircdstate->greeting005b[0]) {
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting005b);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
}
- if (ircdstrings->greeting005c[0]) {
- snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstrings->greeting005c);
+ if (ircdstate->greeting005c[0]) {
+ snprintf(outgoingmsg, MAXDATASIZE, "%s", ircdstate->greeting005c);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
}
// Send our own greeting message
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Welcome to blabouncer!", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Welcome to blabouncer!", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Blabouncer commands are all prefixed with BLABOUNCER which you can usually send using \"/QUOTE BLABOUNCER\"", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Blabouncer commands are all prefixed with BLABOUNCER which you can usually send using \"/QUOTE BLABOUNCER\"", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Valid blabouncer commands are:", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Valid blabouncer commands are:", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER REPLAY [[[[days:]hours:]minutes:]seconds]\" (To replay a given length of time of replay log.)", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER REPLAY [[[[days:]hours:]minutes:]seconds]\" (To replay a given length of time of replay log.)", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER QUIT [quit message]\" (To quit blabouncer, optionally sending [quit message] to the server.)", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER QUIT [quit message]\" (To quit blabouncer, optionally sending [quit message] to the server.)", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
// Get the channel count so we can enumerate over all channels.
@@ -888,7 +888,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
}
// Get client to join channels
- if (!snprintf(outgoingmsg, MAXDATASIZE, "%s JOIN :%s", ircdstrings->nickuserhost, channels[i].name)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, "%s JOIN :%s", ircdstate->nickuserhost, channels[i].name)) {
fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses!\n");
debugprint(DEBUG_CRIT, "Error while preparing USER just connected, channel JOIN responses!\n");
return 0;
@@ -899,7 +899,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// If there isn't one set (we guess this if topic timestamp is 0), send 331 RPL_NOTOPIC
if (strncmp(channels[i].topicwhen, "0", 1) == 0) {
// Prepare the no topic message...
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 331 %s %s :No topic is set.", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 331 %s %s :No topic is set.", ircdstate->ircdname, ircdstate->ircnick, channels[i].name)) {
fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 331 RPL_NOTOPIC!\n");
debugprint(DEBUG_CRIT, "Error while preparing USER just connected, channel JOIN responses, 331 RPL_NOTOPIC!\n");
return 0;
@@ -909,7 +909,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// If there is one set, send 332 RPL_TOPIC and 333 RPL_TOPICWHOTIME
} else {
// Prepare the topic message...
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 332 %s %s :%s", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name, channels[i].topic)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 332 %s %s :%s", ircdstate->ircdname, ircdstate->ircnick, channels[i].name, channels[i].topic)) {
fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 332 RPL_TOPIC!\n");
debugprint(DEBUG_CRIT, "Error while preparing USER just connected, channel JOIN responses, 332 RPL_TOPIC!\n");
return 0;
@@ -918,7 +918,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
// Next prepare the topic who/when message...
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 333 %s %s %s %s", ircdstrings->ircdname, ircdstrings->ircnick, channels[i].name, channels[i].topicwho, channels[i].topicwhen)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s 333 %s %s %s %s", ircdstate->ircdname, ircdstate->ircnick, channels[i].name, channels[i].topicwho, channels[i].topicwhen)) {
fprintf(stderr, "Error while preparing USER just connected, channel JOIN responses, 333 RPL_TOPICWHOTIME!\n");
debugprint(DEBUG_CRIT, "Error while preparing USER just connected, channel JOIN responses, 333 RPL_TOPICWHOTIME!\n");
return 0;
@@ -934,8 +934,8 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
}
// Send our mode to the client (if we have one)
- if (strlen(ircdstrings->mode) > 0) {
- if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s MODE %s %s", ircdstrings->ircnick, ircdstrings->ircnick, ircdstrings->mode)) {
+ if (strlen(ircdstate->mode) > 0) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, ":%s MODE %s %s", ircdstate->ircnick, ircdstate->ircnick, ircdstate->mode)) {
fprintf(stderr, "Error while preparing USER just connected, MODE response!\n");
debugprint(DEBUG_CRIT, "Error while preparing USER just connected, MODE response!\n");
return 0;
@@ -947,8 +947,8 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
clients[arrindex(clients, sourcefd)].registered = 1;
// Catch the client up with the default number of seconds of replay
- if (!doreplay(sourcefd, settings->replayseconds, clients, settings, ircdstrings, channels)) {
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstrings->ircnick);
+ if (!doreplay(sourcefd, settings->replayseconds, clients, settings, ircdstate, channels)) {
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
}
@@ -1006,7 +1006,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// Rebuild to full PRIVMSG string and relay to all other clients
char outgoingmsg[MAXDATASIZE]; // String to send to client
- if (!snprintf(outgoingmsg, MAXDATASIZE, "%s %s", ircdstrings->nickuserhost, str)) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, "%s %s", ircdstate->nickuserhost, str)) {
fprintf(stderr, "Error while preparing PRIVMSG relay from another bouncer client.\n");
debugprint(DEBUG_CRIT, "Error while preparing PRIVMSG relay from another bouncer client.\n");
return 0;
@@ -1038,7 +1038,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// A client has QUIT, so disconnect (close) them and don't do anything else for now - TODO: Let another clients know with a NOTICE or something
if (strncasecmp(tokens[0], "QUIT", strlen(tokens[0])) == 0) {
debugprint(DEBUG_FULL, "Client QUIT found from fd %d and it is: %s with length %zd! Disconnecting that fd.\n", sourcefd, tokens[0], strlen(tokens[0]));
- disconnectclient(sourcefd, clients, ircdstrings, settings);
+ disconnectclient(sourcefd, clients, ircdstate, settings);
return 1;
}
@@ -1117,7 +1117,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// Rebuild to full NOTICE string including our nick!user@host for logging
char fullmsg[MAXDATASIZE];
- if (!snprintf(fullmsg, MAXDATASIZE, "%s %s", ircdstrings->nickuserhost, str)) {
+ if (!snprintf(fullmsg, MAXDATASIZE, "%s %s", ircdstate->nickuserhost, str)) {
fprintf(stderr, "Error while preparing NOTICE string for logging.\n");
debugprint(DEBUG_CRIT, "Error while preparing NOTICE string for logging.\n");
return 0;
@@ -1177,7 +1177,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// Make sure we don't have more than four (d:h:m:s) components
if (timecounter > 4) {
debugprint(DEBUG_SOME, "Too many time components requested by REPLAY command. Telling client.\n");
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Too many time components requestd by REPLAY command. Expected up to four (days:hours:minutes:seconds).", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Too many time components requestd by REPLAY command. Expected up to four (days:hours:minutes:seconds).", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
free(timestrcopyPtr);
return 1;
@@ -1192,7 +1192,7 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
check = strtol(timetokens[i], &str_end, 10);
if (str_end == timetokens[i] || ((check == LONG_MAX || check == LONG_MIN) && errno == ERANGE)) {
debugprint(DEBUG_SOME, "Invalid number '%s' requested by REPLAY command. Telling client.\n", timetokens[i]);
- if (!snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Invalid number '%s' requested by REPLAY command.", ircdstrings->ircnick, timetokens[i])) {
+ if (!snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Invalid number '%s' requested by REPLAY command.", ircdstate->ircnick, timetokens[i])) {
fprintf(stderr, "Error while preparing REPLAY invalid number response!\n");
debugprint(DEBUG_CRIT, "Error while preparing REPLAY invalid number response!\n");
outgoingmsg[0] = '\0';
@@ -1231,8 +1231,8 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
debugprint(DEBUG_FULL, "Replaying '%s' which is '%d' seconds.\n", tokens[2], replayseconds);
- if (!doreplay(sourcefd, replayseconds, clients, settings, ircdstrings, channels)) {
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstrings->ircnick);
+ if (!doreplay(sourcefd, replayseconds, clients, settings, ircdstate, channels)) {
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unable to read replay log file!", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
}
free(timestrcopyPtr);
@@ -1243,19 +1243,19 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int
// Combine "QUIT :" with any optional quit message the user provided
if (counter > 2) {
// Any optional quit message comes 16 characters after the start of the string ("BLABOUNCER QUIT " is 16 characters)
- cleanexit(server_ssl, clients, sourcefd, ircdstrings, settings, str + 16);
+ cleanexit(server_ssl, clients, sourcefd, ircdstate, settings, str + 16);
} else {
- cleanexit(server_ssl, clients, sourcefd, ircdstrings, settings, "");
+ cleanexit(server_ssl, clients, sourcefd, ircdstate, settings, "");
}
// Unrecognised BLABOUNCER command received, send some help instructions
} else {
debugprint(DEBUG_SOME, "Client BLABOUNCER unrecognised command found and it is: %s with length %zd! Sending a help message.\n", tokens[1], strlen(tokens[1]));
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unrecognised BLABOUNCER command received. Valid commands are:", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Unrecognised BLABOUNCER command received. Valid commands are:", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER REPLAY [[[[days:]hours:]minutes:]seconds]\" (To replay a given length of time of replay log.)", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER REPLAY [[[[days:]hours:]minutes:]seconds]\" (To replay a given length of time of replay log.)", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
- snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER QUIT [quit message]\" (To quit blabouncer, optionally sending [quit message] to the server.)", ircdstrings->ircnick);
+ snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :\"BLABOUNCER QUIT [quit message]\" (To quit blabouncer, optionally sending [quit message] to the server.)", ircdstate->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
return 1;
}
diff --git a/message.h b/message.h
index 349a764..b614541 100644
--- a/message.h
+++ b/message.h
@@ -26,12 +26,12 @@
// Process an IRC message that came from the real server.
// Return 1 if we processed it, or 0 if we didn't.
-int processservermessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings,
+int processservermessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstate *ircdstate,
struct channel *channels, struct settings *settings, char tokens[MAXTOKENS][MAXDATASIZE], int counter);
// Process an IRC message that came from a client.
// Return 1 if we processed it, or 0 if we didn't.
-int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings,
+int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int sourcefd, struct ircdstate *ircdstate,
struct channel *channels, struct settings *settings, char tokens[MAXTOKENS][MAXDATASIZE], int counter);
#endif
diff --git a/structures.h b/structures.h
index 5b9c2c0..ac68ba9 100644
--- a/structures.h
+++ b/structures.h
@@ -28,8 +28,7 @@
#define MAXPORTLEN 6 // Up to 65535, so 5 characters + 1 for null
#define MAXAUTOCHANLEN 1024 // Randomly picked maximum length of the auto channel list
-// TODO - Rename this or split into multiple structs since it's no longer strictly just IRCd strings
-struct ircdstrings {
+struct ircdstate {
char greeting001[MAXDATASIZE];
char greeting002[MAXDATASIZE];
char greeting003[MAXDATASIZE];
@@ -55,7 +54,7 @@ struct ircdstrings {
struct settings {
int replayseconds;
char clientport[MAXPORTLEN];
- char ircnick[MAXNICKLENGTH]; // In both settings and ircdstrings as settings is from our file whereas server may change ircdstrings copy
+ char ircnick[MAXNICKLENGTH]; // In both settings and ircdstate as settings is from our file whereas server may change ircdstate copy
char ircusername[MAXUSERNAMELEN]; // (Is this also true for the username? Can the server change that?)
char ircrealname[MAXREALNAMELEN];
char autochannels[MAXAUTOCHANLEN];