diff options
author | Luke Bratch <luke@bratch.co.uk> | 2021-01-18 21:51:00 +0000 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2021-01-18 21:51:00 +0000 |
commit | a16d9bdecb572bb266a84ec90767d613ce8ce255 (patch) | |
tree | 865c745fab117969647ea722334f35304595a7d5 /blabouncer.c | |
parent | 323e273bc7dbc2b244e536a10b6c370651c76b8a (diff) |
Make the "channels" configuration file entry an array.
Diffstat (limited to 'blabouncer.c')
-rw-r--r-- | blabouncer.c | 27 |
1 files changed, 21 insertions, 6 deletions
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); } } |