- hosts[i] = malloc(sizeof(struct monitor_host));
- for (int k=0; k<6; k++) {
- key_buf[section_len] = '\0'; /* Reuse the section name and colon on each pass through this loop. */
- switch (k) {
- case 0:
- strncat(key_buf, "host", MAXCONFKEYLEN);
- hosts[i]->name = strdup(iniparser_getstring(conf, key_buf, NULL));
- break;
- case 1:
- strncat(key_buf, "interval", MAXCONFKEYLEN);
- hosts[i]->ping_interval = iniparser_getint(conf, key_buf, -1);
- break;
- case 2:
- strncat(key_buf, "max_delay", MAXCONFKEYLEN);
- hosts[i]->max_delay = iniparser_getint(conf, key_buf, -1);
- break;
- case 3:
- strncat(key_buf, "up_cmd", MAXCONFKEYLEN);
- hosts[i]->upcmd = strdup(iniparser_getstring(conf, key_buf, NULL));
- break;
- case 4:
- strncat(key_buf, "down_cmd", MAXCONFKEYLEN);
- hosts[i]->downcmd = strdup(iniparser_getstring(conf, key_buf, NULL));
- break;
- case 5:
- /* TODO: Parse for up/down/auto in start_condition. */
- /* TODO: Do a host up/down check if necessary. */
- hosts[i]->hostup = true;
- break;
- }
- }
- /* TODO: Do I want to make any checks for up_cmd, down_cmd, and start_condition? */
- if (hosts[i]->name == NULL || hosts[i]->ping_interval == -1 || hosts[i]->max_delay == -1) {
+ struct host_entry * cur_host = malloc(sizeof(struct host_entry));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "host", MAX_CONF_KEY_LEN);
+ cur_host->name = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "interval", MAX_CONF_KEY_LEN);
+ cur_host->ping_interval = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "max_delay", MAX_CONF_KEY_LEN);
+ cur_host->max_delay = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "up_cmd", MAX_CONF_KEY_LEN);
+ cur_host->up_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "down_cmd", MAX_CONF_KEY_LEN);
+ cur_host->down_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "start_condition", MAX_CONF_KEY_LEN);
+ const char * value = iniparser_getstring(conf, key_buf, NULL);
+ if (value) cur_host->host_up = *value == 'u' ? true : false;
+
+ if (cur_host->name == NULL || cur_host->ping_interval == -1 || cur_host->max_delay == -1) {