summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-12 19:11:30 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-12 19:11:30 +0100
commit34836ab2c9124e17d80bd8e8a1601398297391a8 (patch)
tree3079a0db3bc95c105c04b7730ef0d4c2c4af29c4 /config.c
parent62fe87f6052dc28e38f2edc940b2002ede087277 (diff)
Make client port configurable and move settings structure to be initialised in main() instead of dochat().
Diffstat (limited to 'config.c')
-rw-r--r--config.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/config.c b/config.c
index 7d26ca0..d652147 100644
--- a/config.c
+++ b/config.c
@@ -183,3 +183,45 @@ int checkpassword(char *password) {
printf("No password read from configuration file, quitting.\n");
exit(1);
}
+
+int confclientport(char *clientport) {
+ FILE *fp;
+ char str[MAXCHAR];
+ char* filename = "blabouncer.conf";
+
+ // Set all strings to zero-length to begin
+ clientport[0] = '\0';
+
+ 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, "clientport"))) {
+ getconf(str, len);
+ strncpy(clientport, str, strlen(str));
+ clientport[strlen(str)] = '\0';
+ printf("clientport is: '%s', length '%ld'.\n", clientport, strlen(clientport));
+ }
+ }
+
+ // Ensure we have everything required
+ if (!strlen(clientport)) {
+ printf("Failed to read clientport from configuration file.\n");
+ exit(1);
+ }
+
+ int portint = strtol(clientport, NULL, 10); // Convert resulting string to an integer, base 10
+ // Ensure port is valid
+ if (portint < 1 || portint > 65535) {
+ printf("Invalid clientport value in configuration file.\n");
+ exit(1);
+ }
+
+ fclose(fp);
+ return 1;
+}