summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/functions.c b/functions.c
index 5dd7586..6ed1d2f 100644
--- a/functions.c
+++ b/functions.c
@@ -1027,47 +1027,31 @@ int numclients(struct client *clients) {
// joined in the configuration file.
// Returns 1 on success or 0 on failure.
int joinautochannels(SSL *server_ssl, struct client *clients, struct settings *settings) {
- if (strlen(settings->autochannels) == 0) {
+ if (settings->autochannels[0][0] == '\0') {
// None configured
debugprint(DEBUG_FULL, "joinautochannels(): none configured.\n");
return 1;
}
- // Split string up into each channel
- char tokens[MAXAUTOCHANLEN][MAXCHANLENGTH];
- int counter = 0;
-
- // Copy to a temporary string
- char *strcopy = strdup(settings->autochannels);
- // Keep track of initial pointer for free()ing later
- char *strcopyPtr = strcopy;
-
- char *token;
-
- // Split on commas
- while ((token = strsep(&strcopy, ",")) != NULL) {
- if (*token == '\0') continue; // Skip consecutive matches
- if (counter >= MAXAUTOCHANLEN) break; // Too many tokens
- debugprint(DEBUG_FULL, " >> Auto channel: '%s', length '%ld'.\n", token, strlen(token));
- // Copy into the token array (strlen + 1 to get the NULL terminator)
- strncpy(tokens[counter], token, strlen(token) + 1);
- if (strlen(tokens[counter]) > MAXCHANLENGTH) {
- printf("error: channel name '%s' from configuration file too long, max length is '%d'.\n", tokens[counter], MAXCHANLENGTH);
- debugprint(DEBUG_CRIT, "error: channel name '%s' from configuration file too long, max length is '%d'.\n", tokens[counter], MAXCHANLENGTH);
- exit(1);
+ // Join all the channels
+ for (int i = 0; i < MAXCONFARR; i++) {
+ // Unless there are none left in the array
+ if (settings->autochannels[i][0] == '\0') {
+ debugprint(DEBUG_FULL, "joinautochannels(): Finishing joining %d channels.\n", i);
+ return 1;
}
- counter++;
- }
- // Join all the channels
- for (int i = 0; i < counter; i++) {
- debugprint(DEBUG_FULL, "joinautochannels(): Joining '%s'.\n", tokens[i]);
+ debugprint(DEBUG_FULL, "joinautochannels(): Joining '%s'.\n", settings->autochannels[i]);
char joinmsg[MAXDATASIZE];
- snprintf(joinmsg, MAXDATASIZE, "JOIN %s", tokens[i]);
- sendtoserver(server_ssl, joinmsg, strlen(joinmsg), 0, clients, settings);
+ if (!snprintf(joinmsg, MAXDATASIZE, "JOIN %s", settings->autochannels[i])) {
+ fprintf(stderr, "joinautochannels(): Error while preparing JOIN message!\n");
+ debugprint(DEBUG_CRIT, "joinautochannels(): Error while preparing JOIN message\n");
+ joinmsg[0] = '\0';
+ } else {
+ sendtoserver(server_ssl, joinmsg, strlen(joinmsg), 0, clients, settings);
+ }
}
- free(strcopyPtr);
// TODO - Can we fail here? Return 0 if so and make callers handle this if so.
return 1;
}