summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-16 20:59:51 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-16 20:59:51 +0100
commit968cee422ab1d61b4234127892d75f0497d8d8c2 (patch)
tree16b65ca2c52ec553cb7584d2259f5d3c11ec5902 /blabouncer.c
parenta299b62e913df71bdd1c4b41d61d3fb098f12be7 (diff)
Add a configurable base directory for things like logs, defaulting to $HOME/.blabouncer/.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 3f9004d..59cf8c1 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -16,6 +16,7 @@
// - 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?
//
// Example WHOIS reply:
// BOUNCER-SERVER RECEIVED: :irc.tghost.co.uk 307 blabounce l_bratch :is identified for this nick
@@ -35,6 +36,7 @@
#include <arpa/inet.h>
#include <sys/select.h>
#include <time.h>
+#include <sys/stat.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
@@ -103,6 +105,7 @@ struct settings {
char keyfile[PATH_MAX];
int clienttls;
int servertls;
+ char basedir[PATH_MAX];
};
// Return index of requested client FD within arr_clients
@@ -439,7 +442,7 @@ int doreplay(int sourcefd, int replayseconds, int arr_clients[], int arr_authed[
char outgoingmsg[MAXDATASIZE];
// Figure out how many lines to replay
- int numlines = replaylines(replayseconds);
+ int numlines = replaylines(replayseconds, settings->basedir);
printf("Replay log lines: '%d'.\n", numlines);
if (numlines < 0) {
@@ -453,7 +456,7 @@ int doreplay(int sourcefd, int replayseconds, int arr_clients[], int arr_authed[
// Replay those lines!
for (int i = 0; i < numlines; i++) {
- if (!readreplayline(replayseconds, i, outgoingmsg)) {
+ if (!readreplayline(replayseconds, i, outgoingmsg, settings->basedir)) {
printf("Error requesting replay line.\n");
exit(1);
}
@@ -686,10 +689,10 @@ 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);
+ writereplayline(str, settings->basedir);
// Write to normal log
- logprivmsg(str, settings->ircnick);
+ logprivmsg(str, settings->ircnick, settings->basedir);
return 1;
}
@@ -873,10 +876,10 @@ int processircmessage(SSL *server_ssl, int *clientsockfd, char *str, int source,
sendtoallclients(clientsockfd, fdmax, arr_clients, outgoingmsg, sourcefd, arr_authed, arr_ssl, settings);
// Write to replay log
- writereplayline(outgoingmsg);
+ writereplayline(outgoingmsg, settings->basedir);
// Write to normal log
- logprivmsg(outgoingmsg, settings->ircnick);
+ logprivmsg(outgoingmsg, settings->ircnick, settings->basedir);
return 1;
}
@@ -1438,6 +1441,22 @@ int main(int argc, char *argv[]) {
}
}
+ // Is the base directory set? If not, use the default.
+ if (!getconfstr("basedir", settings.conffile, settings.basedir)) {
+ snprintf(settings.basedir, PATH_MAX, "%s/.blabouncer/", getenv("HOME"));
+ }
+
+ // Make sure the base directory exists
+ struct stat st = {0};
+ if (stat(settings.basedir, &st) == -1) {
+ if (mkdir(settings.basedir, 0700)) {
+ printf("Error creating base directory '%s'.\n", settings.basedir);
+ exit(1);
+ } else {
+ printf("Created base directory '%s'.\n", settings.basedir);
+ }
+ }
+
// 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 (?)