summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-11 19:03:57 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-11 19:03:57 +0100
commit0559bff00a6be2054194632c3543bf62af1fb56f (patch)
treef007a35d1d7af9a7fa1166831b982c84111baad7 /config.c
parentc46d01b5afd2da4779efb2700469037eca6122be (diff)
Add the ability to replay messages from a replay log file. (No replay log file writing yet.)
Diffstat (limited to 'config.c')
-rw-r--r--config.c41
1 files changed, 39 insertions, 2 deletions
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;
+}