diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-16 20:59:51 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-16 20:59:51 +0100 |
commit | 968cee422ab1d61b4234127892d75f0497d8d8c2 (patch) | |
tree | 16b65ca2c52ec553cb7584d2259f5d3c11ec5902 /replay.c | |
parent | a299b62e913df71bdd1c4b41d61d3fb098f12be7 (diff) |
Add a configurable base directory for things like logs, defaulting to $HOME/.blabouncer/.
Diffstat (limited to 'replay.c')
-rw-r--r-- | replay.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -137,10 +137,14 @@ void formattime(char *str) { } // Return the number of lines in the replay log since 'seconds' seconds ago, or -1 if there a problem. -int replaylines(int seconds) { +// 'basedir' is the directory in which to find 'replay.log'. +int replaylines(int seconds, char *basedir) { FILE *fp; char str[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int numlines = 0; @@ -175,14 +179,18 @@ int replaylines(int seconds) { } // Set 'str' to the line in the log with a timestamp of greater than 'seconds' -// seconds ago, plus however many lines 'linenum' is set to. +// seconds ago, plus however many lines 'linenum' is set to. 'basedir' is the +// directory in which to find 'replay.log'. // Also modify the line to include a timestamp in the form "[HH:MM:SS]". // Returns 1 on success, or 0 on failure. // TODO - This is horribly inefficient since it re-reads the entire file each call, rewrite this! -int readreplayline(int seconds, int linenum, char *str) { +int readreplayline(int seconds, int linenum, char *str, char *basedir) { FILE *fp; char line[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int count = 0; @@ -226,15 +234,19 @@ int readreplayline(int seconds, int linenum, char *str) { } // Write the line 'str' to the replay log file after prepending it with -// the current unixtime timestamp. +// the current unixtime timestamp. 'basedir' is the directory in which +// to write to 'replay.log'. // Expects a string in the format: // :from!bar@baz PRIVMSG to :hello world // With the ":foo!bar@baz "prefix being important. // Returns 1 on success or 0 on failure. -int writereplayline(char *str) { +int writereplayline(char *str, char *basedir) { FILE *fp; char line[MAXCHAR]; - char* filename = "replay.log"; + char filename[PATH_MAX]; + + // Build path + snprintf(filename, PATH_MAX, "%s/replay.log", basedir); int bytes = 0; |