From a16d9bdecb572bb266a84ec90767d613ce8ce255 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Mon, 18 Jan 2021 21:51:00 +0000 Subject: Make the "channels" configuration file entry an array. --- blabouncer.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'blabouncer.c') diff --git a/blabouncer.c b/blabouncer.c index 982d504..89add3e 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -1052,12 +1052,27 @@ int main(int argc, char *argv[]) { } // What, if anything, are the configured auto channels? - if (!getconfstr("channels", settings.conffile, settings.autochannels)) { - settings.autochannels[0] = '\0'; - } else { - // If something was set, make sure it's not too long - if (strlen(settings.autochannels) >= MAXAUTOCHANLEN) { - printf("main(): 'channels' option in configuration file is too long.\n"); + ret = getconfarr("channels", settings.conffile, settings.autochannels); + if (!ret) { + for (int i = 0; i < MAXCONFARR; i++) { + settings.autochannels[i][0] = '\0'; + } + } else if (ret == -1) { + // Remove any newlines from the middle of the string so error printing works nicely + for (size_t i = 0; i < strlen(settings.autochannels[0]) - 1; i++) { + if (settings.autochannels[0][i] == '\n') { + settings.autochannels[0][i] = ' '; + } + } + printf("main(): error getting 'autochannels' from configuration file: %s", settings.autochannels[0]); + exit(1); + } + + // Make sure channel/key pairs aren't too long (since getconfarr() has to use MAXDATASIZE for all string lengths) + for (int i = 0; i < MAXCONFARR; i++) { + // +1 for the space between channel name and keys + if (settings.autochannels[i][0] && strlen(settings.autochannels[i]) > MAXCHANLENGTH + 1 + MAXCHANKEYLEN) { + printf("main(): error: specified channel name/key pair '%s' is too long, maximum lengths are %d (name) and %d (key).\n", settings.autochannels[i], MAXCHANLENGTH, MAXCHANKEYLEN); exit(1); } } -- cgit v1.2.3