summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-16 21:50:35 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-16 21:50:35 +0100
commitcfe9c969680a7a09ee60cf048f71b81d82bef1df (patch)
treeb035bf87184f3168722acf97e0a043bf2d00f2f6
parent61a369b85e51e0d54e1651e4ff8c11fe4815a0c0 (diff)
Make logging and replay logging optional.
-rw-r--r--blabouncer.c33
-rw-r--r--blabouncer.conf8
-rw-r--r--config.c10
3 files changed, 41 insertions, 10 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 8ed8d72..41e0a47 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -13,7 +13,6 @@
// - Configurable auto channels
// - Comma separated channel list in JOINs/PARTs
// - Only send some things to the requesting client (e.g. LIST replies)
-// - Customise logging (disabling it, log file location)
// - Alert when clients connect/authenticate/disconnect
// - Perhaps rename arr_ssl and server_ssl since they may not even be OpenSSL sockets
// - Is it possible to replay JOINs/PARTs accurately?
@@ -106,6 +105,8 @@ struct settings {
int clienttls;
int servertls;
char basedir[PATH_MAX];
+ int logging;
+ int replaylogging;
};
// Return index of requested client FD within arr_clients
@@ -688,11 +689,15 @@ int processircmessage(SSL *server_ssl, int *clientsockfd, char *str, int source,
sendtoallclients(clientsockfd, fdmax, arr_clients, str, sourcefd, arr_authed, arr_ssl, settings);
- // Write to replay log
- writereplayline(str, settings->basedir);
+ // Write to replay log if replay logging enabled
+ if (settings->replaylogging) {
+ writereplayline(str, settings->basedir);
+ }
- // Write to normal log
- logprivmsg(str, settings->ircnick, settings->basedir);
+ // Write to normal log if logging enabled
+ if (settings->logging) {
+ logprivmsg(str, settings->ircnick, settings->basedir);
+ }
return 1;
}
@@ -875,11 +880,15 @@ int processircmessage(SSL *server_ssl, int *clientsockfd, char *str, int source,
// Send to all except source client
sendtoallclients(clientsockfd, fdmax, arr_clients, outgoingmsg, sourcefd, arr_authed, arr_ssl, settings);
- // Write to replay log
- writereplayline(outgoingmsg, settings->basedir);
+ // Write to replay log if replay logging enabled
+ if (settings->replaylogging) {
+ writereplayline(outgoingmsg, settings->basedir);
+ }
- // Write to normal log
- logprivmsg(outgoingmsg, settings->ircnick, settings->basedir);
+ // Write to normal log if logging enabled
+ if (settings->logging) {
+ logprivmsg(outgoingmsg, settings->ircnick, settings->basedir);
+ }
return 1;
}
@@ -1464,6 +1473,12 @@ int main(int argc, char *argv[]) {
}
}
+ // Is logging enabled?
+ settings.logging = getconfint("logging", settings.conffile);
+
+ // Is replay logging enabled?
+ settings.replaylogging = getconfint("replaylogging", settings.conffile);
+
// TODO: see if any of this can be shared (i.e. 1. avoid code duplication, and 2. see if variables can be shared between client/server sockets)
// TODO: track fdmax - kind of doing this now with arr_clients and num_clients but might be pointlessly tracking both in some places (?)
diff --git a/blabouncer.conf b/blabouncer.conf
index cf9591b..b834c8e 100644
--- a/blabouncer.conf
+++ b/blabouncer.conf
@@ -41,3 +41,11 @@ keyfile = "key.pem"
# Base directory (defaults to $HOME/.blabouncer/)
# Things such as the logs directory will be placed below this
#basedir = "/home/foo/.blabouncer/"
+
+# Enable logging ("1" for yes or "0" for no)
+# Logs go to basedir/logs/ with one file per channel/nick
+logging = "1"
+
+# Enable replay logging ("1" for yes or "0" for no)
+# Replay log goes to basedir/replay.log
+replaylogging = "1"
diff --git a/config.c b/config.c
index a5d9c2f..60bac19 100644
--- a/config.c
+++ b/config.c
@@ -201,7 +201,15 @@ int createconfigfile(char *filename) {
"\n"
"# Base directory (defaults to $HOME/.blabouncer/)\n"
"# Things such as the logs directory will be placed below this\n"
- "#basedir = \"/home/foo/.blabouncer/\"\n";
+ "#basedir = \"/home/foo/.blabouncer/\"\n"
+ "\n"
+ "# Enable logging (\"1\" for yes or \"0\" for no)\n"
+ "# Logs go to basedir/logs/ with one file per channel/nick\n"
+ "logging = \"1\"\n"
+ "\n"
+ "# Enable replay logging (\"1\" for yes or \"0\" for no)\n"
+ "# Replay log goes to basedir/replay.log\n"
+ "replaylogging = \"1\"\n";
// Write complete string to file
if ((fprintf(fp, string)) < 0) {