summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
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;
+}