summaryrefslogtreecommitdiff
path: root/message.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-11 19:50:17 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-11 19:50:17 +0100
commit9db9fb396aaf601bd00f2b62face2693307a0e16 (patch)
tree2c5603a723899c0f5a4ec129cdaee1e5b1f6b556 /message.c
parentf660bbd1bfed3fbd36d684cd2f09ca1520520557 (diff)
Refactoring - rename ircdstrings struct to ircdstate since it doesn't just contain strings.
Diffstat (limited to 'message.c')
-rw-r--r--message.c244
1 files changed, 122 insertions, 122 deletions
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;
}