diff options
-rw-r--r-- | TODO | 17 | ||||
-rw-r--r-- | functions.c | 60 | ||||
-rw-r--r-- | functions.h | 14 | ||||
-rw-r--r-- | logging.c | 18 | ||||
-rw-r--r-- | message.c | 16 | ||||
-rw-r--r-- | replay.c | 5 |
6 files changed, 84 insertions, 46 deletions
@@ -6,4 +6,19 @@ Add a make install/uninstall/etc., add an "INSTALL" file, include a dependency l macOS compiler may need limits.h included in structures.h. -replaymode = "lastspoke" causes huge amounts of spam from extractnickfromprefix() and friends in full debug mode. +"Starting log replay...." followed by "Unable to read replay log file!" even though replay seemed to work? + +NAMES don't seem to be sent to clients (at least old irssi) after weird timeouts like slow QUIT processing. + +Memory usage seems very high. Maybe it's timeouts/reconnecting? Does it only happen with background mode? + +When blabouncer reconnects to a server, clients (at least XChat) get stuck with just e.g. +[13:14:50]* PONG LAG1574032890090568 +[13:15:20]* PONG LAG1574032920149401 +[13:15:50]* PONG LAG1574032950205568 +[13:16:20]* PONG LAG1574032980263198 +[13:16:50]* PONG LAG1574033010319500 +[13:17:20]* PONG LAG1574033040377501 +In channels with no nicks. + +Add BLABOUNCER VERSION. diff --git a/functions.c b/functions.c index c5e3cdc..28c6691 100644 --- a/functions.c +++ b/functions.c @@ -179,12 +179,16 @@ void appendcrlf(char *string) { } // Remove leading colon ':' which is the starting character of a prefix in an IRC message -// If no leading colon present, string is left unchanged -void stripprefix(char *string) { +// If no leading colon present, string is left unchanged. +// "debug" is used to determine whether stripprefix() should produce all debug output, +// used as debug output with stripprefix() can be particularly noisy. +void stripprefix(char *string, int debug) { // Make a copy to work with char string2[strlen(string)]; - debugprint(DEBUG_FULL, "stripprefix(): starting with '%s', strlen: %zd.\n", string, strlen(string)); + if (debug) { + debugprint(DEBUG_FULL, "stripprefix(): starting with '%s', strlen: %zd.\n", string, strlen(string)); + } // Don't bother if this isn't a prefix with a leading ':' if (string[0] != ':') { @@ -203,7 +207,9 @@ void stripprefix(char *string) { // Finish with null terminator string[strlen(string) - 1] = '\0'; - debugprint(DEBUG_FULL, "stripprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); + if (debug) { + debugprint(DEBUG_FULL, "stripprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); + } } // Extract final parameter from IRC message, removing the leading colon ':' @@ -221,7 +227,7 @@ void extractfinalparameter(char *string) { debugprint(DEBUG_FULL, "extractfinalparameter(): starting with '%s', strlen: %zd.\n", string, strlen(string)); // Strip the colon at position 0 if there is one - stripprefix(string); + stripprefix(string, 1); // Find the colon for (size_t i = 0; i < strlen(string); i++) { @@ -258,33 +264,41 @@ void extractfinalparameter(char *string) { // ":foo!bar@baz" // We want to end up with: // "foo" -void extractnickfromprefix(char *string) { +// "debug" is used to determine whether extractnickfromprefix() should produce all debug output, +// used as debug output with extractnickfromprefix() can be particularly noisy. +void extractnickfromprefix(char *string, int debug) { // Position of bang int bangpos = -1; - debugprint(DEBUG_FULL, "extractnickfromprefix(): starting with '%s', strlen: %zd.\n", string, strlen(string)); + if (debug) { + debugprint(DEBUG_FULL, "extractnickfromprefix(): starting with '%s', strlen: %zd.\n", string, strlen(string)); + } - // Strip the colon at position 0 if there is one - stripprefix(string); + // Strip the colon at position 0 if there is one, debugging enabled/disabled based on "debug" pass to us + stripprefix(string, debug); // Find the bang for (size_t i = 0; i < strlen(string); i++) { if (string[i] == '!') { - debugprint(DEBUG_FULL, "Found bang at position %zd!\n", i); + if (debug) { + debugprint(DEBUG_FULL, "extractnickfromprefix(): found bang at position %zd!\n", i); + } bangpos = i; break; } } if (bangpos == -1) { - debugprint(DEBUG_FULL, "no bang found, returning\n"); + debugprint(DEBUG_FULL, "extractnickfromprefix(): no bang found, returning...\n"); return; } // Terminate the string at whatever position we found the bang string[bangpos] = '\0'; - debugprint(DEBUG_FULL, "extractnickfromprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); + if (debug) { + debugprint(DEBUG_FULL, "extractnickfromprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); + } } // Update an existing nickuserhost string with a new nick @@ -330,10 +344,10 @@ void updategreetings(char *greeting001, char *greeting002, char *greeting003, ch // Make copies of the nickuserhosts to work with char newnickuserhostcpy[MAXDATASIZE]; strcpy(newnickuserhostcpy, newnickuserhost); - stripprefix(newnickuserhostcpy); + stripprefix(newnickuserhostcpy, 1); char oldnickuserhostcpy[MAXDATASIZE]; strcpy(oldnickuserhostcpy, oldnickuserhost); - stripprefix(oldnickuserhostcpy); + stripprefix(oldnickuserhostcpy, 1); // Find the position of the old nickuserhost in the current greeting 001 char *ret; @@ -359,7 +373,7 @@ void updategreetings(char *greeting001, char *greeting002, char *greeting003, ch char newnickcpy[MAXDATASIZE]; strcpy(newnickcpy, newnick); - extractnickfromprefix(newnickcpy); + extractnickfromprefix(newnickcpy, 1); // greeting nicks next // (as in ":servername 00x oldnick :Blablabla" -> ":servername 00x newnick :Blablabla") @@ -866,7 +880,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set } // To make sure it's not us - extractnickfromprefix(tokens[0]); + extractnickfromprefix(tokens[0], 1); // 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], ircdstate->ircnick, strlen(tokens[0])) == 0) { @@ -878,7 +892,7 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set // Separate special check for if a NICK change is from us but it isn't our current nick if (strncmp(tokens[1], "NICK", strlen("NICK")) == 0) { - extractnickfromprefix(tokens[0]); + extractnickfromprefix(tokens[0], 1); if (strncmp(tokens[0], ircdstate->ircnick, strlen(tokens[0])) == 0) { debugprint(DEBUG_FULL, "Not sending '%s' replay line '%s'.\n", tokens[1], outgoingmsg); @@ -1338,7 +1352,7 @@ int addnicktochannel(char *nickuserhost, char *channel, struct channel *channels debugprint(DEBUG_FULL, "addnicktochannel(): given '%s' and '%s'.\n", nickuserhost, channel); // Get the nick from the prefix - extractnickfromprefix(nickuserhost); + extractnickfromprefix(nickuserhost, 1); // Make sure the channel exists int chanfound = 0; @@ -1383,7 +1397,7 @@ int removenickfromchannel(char *nickuserhost, char *channel, struct channel *cha debugprint(DEBUG_FULL, "removenickfromchannel(): given '%s' and '%s'.\n", nickuserhost, channel); // Get the username from the prefix - extractnickfromprefix(nickuserhost); + extractnickfromprefix(nickuserhost, 1); // Make sure the channel exists int chanfound = 0; @@ -1422,7 +1436,7 @@ int removenickfromallchannels(char *nickuserhost, struct channel *channels) { debugprint(DEBUG_FULL, "removenickfromallchannels(): given '%s'.\n", nickuserhost); // Get the nick from the prefix - extractnickfromprefix(nickuserhost); + extractnickfromprefix(nickuserhost, 1); // Make sure the nick has a length of at least one if (strlen(nickuserhost) < 1) { @@ -1456,10 +1470,10 @@ int updatenickinallchannels(char *nickuserhost, char *newnick, struct channel *c debugprint(DEBUG_FULL, "updatenickinallchannels(): given '%s' and '%s'.\n", nickuserhost, newnick); // Get the nick from the prefix - extractnickfromprefix(nickuserhost); + extractnickfromprefix(nickuserhost, 1); // Strip prefix from newnick - stripprefix(newnick); + stripprefix(newnick, 1); // Make sure the old and new nicks have a length of at least one if (strlen(nickuserhost) < 1 || strlen(newnick) < 1) { @@ -1493,7 +1507,7 @@ int addnamereplytochannel(char *namereply, struct channel *channels) { strcpy(strcopy, namereply); // Strip the leading ':' - stripprefix(strcopy); + stripprefix(strcopy, 1); // Find the start of the channel name, which comes after the first '=' followed by a space int channelpos = -1; diff --git a/functions.h b/functions.h index 420e03f..7a3e398 100644 --- a/functions.h +++ b/functions.h @@ -69,14 +69,22 @@ int getstdin(char *prompt, char *buff, size_t sz); void appendcrlf(char *string); // Remove leading colon ':' which is the starting character of a prefix in an IRC message -// If no leading colon present, string is left unchanged -void stripprefix(char *string); +// If no leading colon present, string is left unchanged. +// "debug" is used to determine whether stripprefix() should produce all debug output, +// used as debug output with stripprefix() can be particularly noisy. +void stripprefix(char *string, int debug); // Extract final parameter from IRC message, removing the leading colon ':' void extractfinalparameter(char *string); // Extract the IRC nick from a prefix -void extractnickfromprefix(char *string); +// e.g. given this string: +// ":foo!bar@baz" +// We want to end up with: +// "foo" +// "debug" is used to determine whether extractnickfromprefix() should produce all debug output, +// used as debug output with extractnickfromprefix() can be particularly noisy. +void extractnickfromprefix(char *string, int debug); // Update an existing nickuserhost string with a new nick void updatenickuserhost(char *nickuserhost, char *nick); @@ -126,11 +126,11 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { switch(type) { case LOG_PRIVMSG: // Extract the username from the prefix - extractnickfromprefix(tokens[0]); - extractnickfromprefix(from); + extractnickfromprefix(tokens[0], 1); + extractnickfromprefix(from, 1); // Remove the leading ":" from the real message - stripprefix(str); + stripprefix(str, 1); // Build the log filename // If the message was sent to us, then log it in the sender's log file @@ -211,10 +211,10 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { case LOG_TOPIC: // Extract the username from the prefix - extractnickfromprefix(tokens[0]); + extractnickfromprefix(tokens[0], 1); // Remove the leading ":" from the topic - stripprefix(str); + stripprefix(str, 1); if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, to)) { debugprint(DEBUG_CRIT, "Error while preparing log filename for topic, returning!\n"); @@ -265,7 +265,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { tokens[1][posbang] = '\0'; // Strip the prefix from the quit message - stripprefix(str); + stripprefix(str, 1); // Build a friendly message (e.g. "nick (user@host) has quit (Quit: message)") snprintf(line, MAXCHAR, "%s (%s) has quit (%s)", tokens[1] + 1, tokens[1] + posbang + 1, str); @@ -280,9 +280,9 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { case LOG_NICK: // Extract old nick from the prefix - extractnickfromprefix(tokens[1]); + extractnickfromprefix(tokens[1], 1); // Strip colon from new nick - stripprefix(str); + stripprefix(str, 1); // Build a friendly message (e.g. "oldnick is now known as newnick") snprintf(line, MAXCHAR, "%s is now known as %s", tokens[1], str); @@ -297,7 +297,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { case LOG_MODE: // Extract nick from prefix - extractnickfromprefix(tokens[0]); + extractnickfromprefix(tokens[0], 1); // Build a friendly message (e.g. "nick sets mode #channel +ov nick1 nick2") if (!snprintf(line, MAXCHAR, "%s sets mode %s %s", tokens[0], tokens[2], str)) { @@ -185,14 +185,14 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int debugprint(DEBUG_FULL, "Server JOIN found and it is: %s with length %zd! Next token is '%s'. Adding to local channel list if it's us.\n", tokens[0], strlen(tokens[0]), tokens[2]); // Next token should be the channel name but it probably needs the leading ':' stripping debugprint(DEBUG_FULL, "processircmessage(): Channel name was '%s'\n", tokens[2]); - stripprefix(tokens[2]); + stripprefix(tokens[2], 1); debugprint(DEBUG_FULL, "processircmessage(): Channel name now '%s'\n", tokens[2]); // If the user JOINing is us, then we must have joined a channel, so add to our local channel array. // Copy to a temporary string so we still have the original in case we need it char *prefixcopy = strdup(tokens[0]); // Just get the nick for comparison - extractnickfromprefix(prefixcopy); + extractnickfromprefix(prefixcopy, 1); 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? @@ -233,7 +233,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int // Copy to a temporary string so we still have the original in case we need it char *prefixcopy = strdup(tokens[0]); // Just get the nick for comparison - extractnickfromprefix(prefixcopy); + extractnickfromprefix(prefixcopy, 1); 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]); @@ -279,7 +279,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int if (settings->logging) { char quitnick[MAXDATASIZE]; strcpy(quitnick, tokens[0]); - extractnickfromprefix(quitnick); + extractnickfromprefix(quitnick, 1); for (int i = 0; i < MAXCHANNELS; i++) { if (channels[i].name[0]) { for (int j = 0; j < MAXCHANNICKS; j++) { @@ -396,7 +396,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int // Extract the topic setter from the prefix (Prefix of ":foo!bar@baz" means "foo" set the topic.) // Copy to a temporary string so we still have the original in case we need it char *prefixcopy = strdup(tokens[0]); - extractnickfromprefix(prefixcopy); + extractnickfromprefix(prefixcopy, 1); // Get the current time and manipulate it into a C string time_t timenow = time(NULL); @@ -456,7 +456,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int // Copy to a temporary string so we still have the original in case we need it char *svrprefixcopy = strdup(tokens[0]); // Just get the nick for comparison - extractnickfromprefix(svrprefixcopy); + extractnickfromprefix(svrprefixcopy, 1); 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 @@ -468,7 +468,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int // Temporary copy of new nickuserhost char *prefixcopy = strdup(ircdstate->nickuserhost); // Get nick from it - extractnickfromprefix(prefixcopy); + extractnickfromprefix(prefixcopy, 1); // Update greeting strings for relaying to new clients updategreetings(ircdstate->greeting001, ircdstate->greeting002, ircdstate->greeting003, ircdstate->greeting004, ircdstate->greeting005a, ircdstate->greeting005b, ircdstate->greeting005c, ircdstate->nickuserhost, @@ -492,7 +492,7 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int if (settings->logging) { char oldnick[MAXDATASIZE]; strcpy(oldnick, tokens[0]); - extractnickfromprefix(oldnick); + extractnickfromprefix(oldnick, 1); for (int i = 0; i < MAXCHANNELS; i++) { if (channels[i].name[0]) { for (int j = 0; j < MAXCHANNICKS; j++) { @@ -352,8 +352,9 @@ int lastspokesecondsago(char *nick, char *basedir) { continue; } - // Was it said by our 'nick'? - extractnickfromprefix(tokens[1]); + // Was it said by our 'nick'? Disable extractnickfromprefix() debugging + // as it gets very noisy when we call it from here. + extractnickfromprefix(tokens[1], 0); if (strncmp(tokens[1], nick, strlen(nick))) { // Not our 'nick', continue continue; |