summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-12-22 16:01:16 +0000
committerLuke Bratch <luke@bratch.co.uk>2019-12-22 16:01:16 +0000
commit85dd88a180043e991c19a4c93a6ce5c7fe0a6e88 (patch)
tree2866cf5772eb3e0e2da4be0a86fc5a07b499b174 /functions.c
parent2385f7b944bb22acd85e6c089e509880a45a2cb1 (diff)
Make full debug output optional for extractnickfromprefix() and stripprefix() to avoid huge debug logs when using replaymode = "lastspoke" combined with DEBUG_FULL.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c60
1 files changed, 37 insertions, 23 deletions
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;