From 0559bff00a6be2054194632c3543bf62af1fb56f Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 11 May 2019 19:03:57 +0100 Subject: Add the ability to replay messages from a replay log file. (No replay log file writing yet.) --- config.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index ca6b158..7fec4de 100644 --- a/config.c +++ b/config.c @@ -1,5 +1,9 @@ #include "config.h" +// TODO - Multiple functions here (at least readnames() and relayseconds() have the file opening code, rewrite. + +// TODO - Can isconf() and getconf() just be merged into one function? + // Check to see if a line is the configuration option specified by // checking to see if str starts with conf followed by a space, a tab, // or an equals sign. @@ -69,9 +73,10 @@ int readnames(char *nick, char *username, char *realname) { fp = fopen(filename, "r"); if (fp == NULL) { - printf("error: could not open configuration file '%s.'", filename); - return 1; + printf("error: could not open configuration file '%s'.\n", filename); + exit(1); } + while (fgets(str, MAXCHAR, fp) != NULL) { long int len; if ((len = isconf(str, "nick"))) { @@ -101,3 +106,35 @@ int readnames(char *nick, char *username, char *realname) { fclose(fp); return 1; } + +// Return the relayseconds configuration option +// (How many seconds of relay should be sent to connecting clients) +int confrelayseconds() { + FILE *fp; + char str[MAXCHAR]; + char* filename = "blabouncer.conf"; + + char secondsstr[MAXCHAR]; + int seconds; + + fp = fopen(filename, "r"); + + if (fp == NULL) { + printf("error: could not open configuration file '%s'.\n", filename); + exit(1); + } + + while (fgets(str, MAXCHAR, fp) != NULL) { + long int len; + if ((len = isconf(str, "relayseconds"))) { + getconf(str, len); + strncpy(secondsstr, str, strlen(str)); + secondsstr[strlen(str)] = '\0'; + printf("secondsstr is: '%s', length '%ld'.\n", secondsstr, strlen(secondsstr)); + seconds = strtol(secondsstr, NULL, 10); // Convert resulting string to an integer, base 10 + printf("seconds is: '%d'.\n", seconds); + } + } + + return seconds; +} -- cgit v1.2.3