diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 21:36:31 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-12 21:36:31 +0100 |
commit | 03b15b2a99dee16998d08e17652bb49555c8560d (patch) | |
tree | 2ba2ea430e1c2ed05c5e9b68c2f7b0d9b925ea70 | |
parent | dba30066da1c929a140281cbbb6a8f177fdf14d4 (diff) |
Make configuration file path configurable on the command line. Also finish removing the non-functional debug() stuff.
-rw-r--r-- | blabouncer.c | 39 | ||||
-rw-r--r-- | functions.c | 8 | ||||
-rw-r--r-- | functions.h | 3 |
3 files changed, 28 insertions, 22 deletions
diff --git a/blabouncer.c b/blabouncer.c index a370d71..13e91c1 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -70,8 +70,6 @@ #define MAXREALNAMELEN 128 // Randomly picked (TODO - is there an actual maximum real name length?) #define MAXPORTLEN 6 // Up to 65535, so 5 characters + 1 for null -#define CONFFILE "blabouncer.conf" - struct channel { char name[MAXCHANLENGTH]; char topic[MAXDATASIZE]; // TODO - Is there a particular maximum topic length? @@ -105,6 +103,7 @@ struct settings { char ircrealname[MAXREALNAMELEN]; char ircserver[HOST_NAME_MAX]; char ircserverport[MAXPORTLEN]; + char conffile[PATH_MAX]; }; // Return index of requested client FD within arr_clients @@ -669,7 +668,7 @@ int processircmessage(int *serversockfd, int *clientsockfd, char *str, int sourc case SOURCE_CLIENT: // If message(s) were from a real IRC client // PASS received? User is trying to log in, check their password. if (strncmp(tokens[0], "PASS", strlen(tokens[0])) == 0) { - if (checkpassword(tokens[1], CONFFILE)) { + if (checkpassword(tokens[1], settings->conffile)) { printf("Password accepted! Setting fd %d to authenticated.\n", sourcefd); // Find the client in the clients array and set them as authenticated for (int i = 0; i < MAXCLIENTS; i++) { @@ -1271,42 +1270,60 @@ int main(int argc, char *argv[]) { // Structure of our various settings which are to either be read from the configuration file or set at runtime struct settings settings; - // Populate said settings + // Check to see if a configuration file was specified on the command line + if (argc == 3) { + if (strcmp(argv[1], "-c")) { + fprintf(stderr,"usage: %s [-c /path/to/blabouncer.conf]\n", argv[0]); + exit(1); + } else { + strcpy(settings.conffile, argv[2]); + } + } else if (argc == 2 || argc > 3) { + fprintf(stderr,"usage: %s [-c /path/to/blabouncer.conf]\n", argv[0]); + exit(1); + } else { + // If none provided, set to default + strcpy(settings.conffile, "blabouncer.conf"); + } + + printf("Using configuration file '%s'.\n", settings.conffile); + + // Populate said settings from configuration file // How many seconds of replay log should automatically be replayed - TODO - Can we do error checking on this? - settings.replayseconds = getconfint("replayseconds", CONFFILE); + settings.replayseconds = getconfint("replayseconds", settings.conffile); // What port should the bouncer listen on - if (!getconfstr("clientport", CONFFILE, settings.clientport)) { + if (!getconfstr("clientport", settings.conffile, settings.clientport)) { printf("main(): error getting 'clientport' from configuration file.\n"); exit(1); } // What is the configured nick? - if (!getconfstr("nick", CONFFILE, settings.ircnick)) { + if (!getconfstr("nick", settings.conffile, settings.ircnick)) { printf("main(): error getting 'nick' from configuration file.\n"); exit(1); } // What is the configured username? - if (!getconfstr("username", CONFFILE, settings.ircusername)) { + if (!getconfstr("username", settings.conffile, settings.ircusername)) { printf("main(): error getting 'username' from configuration file.\n"); exit(1); } // What is the configured real name? - if (!getconfstr("realname", CONFFILE, settings.ircrealname)) { + if (!getconfstr("realname", settings.conffile, settings.ircrealname)) { printf("main(): error getting 'realname' from configuration file.\n"); exit(1); } // What is the real IRC server address? - if (!getconfstr("ircserver", CONFFILE, settings.ircserver)) { + if (!getconfstr("ircserver", settings.conffile, settings.ircserver)) { printf("main(): error getting 'ircserver' from configuration file.\n"); exit(1); } // What is the real IRC server port? - if (!getconfstr("ircserverport", CONFFILE, settings.ircserverport)) { + if (!getconfstr("ircserverport", settings.conffile, settings.ircserverport)) { printf("main(): error getting 'ircserverport' from configuration file.\n"); exit(1); } diff --git a/functions.c b/functions.c index 1d7d7d6..e43f31c 100644 --- a/functions.c +++ b/functions.c @@ -1,13 +1,5 @@ #include "functions.h" -// Print a debugging message, if debugging enabled -int debugmode; -void debug(char *string) { - if (debugmode) { - printf("DEBUG: %s\n", string); - } -} - // Get stdin line with buffer overrun protection int getstdin(char *prompt, char *buff, size_t sz) { int ch, extra; diff --git a/functions.h b/functions.h index f12e13f..4e525eb 100644 --- a/functions.h +++ b/functions.h @@ -18,9 +18,6 @@ #define NO_INPUT 1 #define TOO_LONG 2 -// Print a debugging message, if debugging enabled -void debug(char *string); - // Get stdin line with buffer overrun protection int getstdin(char *prompt, char *buff, size_t sz); |