struct cfg_list *cfg_get_list(char *section, char *subsection) { struct cfg_section *current; if ((current = cfg_get_section(section, subsection))) return current->list; return NULL; }
int cfg_print_section_list_lines(char *section, char *subsection) { struct cfg_section *current; struct cfg_line *line; int line_count = 0; if ((current = cfg_get_section(section, subsection))) { if (current->list && (line = current->list->head)) do { // we only want to see the line contents // printf("%s-%d_%d:%s\n", line->cfg_name, line->id, line->number, line->data); printf("%s\n", line->data); line_count++; } while((line = line->next)); return line_count; } else return -1; }
char *cfg_get_param(char *section, char *subsection, char *param) { struct cfg_section *current_section; struct cfg_param *current_param; char *p1, *p2; if ((current_section = cfg_get_section(section, subsection))) if ((current_param = current_section->params)) do { p1 = current_param->name; p2 = param; while (*p1 && *p1 == tolower((int)(unsigned char)*p2)) { p1++; p2++; } if (*p1 || *p2) continue; return current_param->value; } while ((current_param = current_param->next)); return NULL; }
int cfg_print_section_params(char *section, char *subsection) { struct cfg_section *current; struct cfg_param *param; char *value; int param_count = 0; if ((current = cfg_get_section(section, subsection))) { if((param = current->params)) do { value = cfg_get_param(section, subsection, param->name); if(!strcmp(param->value, value)) { printf("%s = %s\n", param->name, param->value); param_count++; } } while ((param = param-> next)); return param_count; } else return -1; }
// Handle .include [section] static int cfg_process_directive_include_section(char *line, int number) { struct cfg_section *newsection; char *p = &line[10]; char *p2 = strchr(&p[1], ']'); char Section[256]; if (!p2) { fprintf(stderr, "ERROR, invalid config include line: %s\n", line); #ifndef BENCH_BUILD log_event ("! Error, invalid config include line: %s", line); #endif return 1; } if (!cfg_database || !cfg_database->name) { fprintf(stderr, "ERROR, invalid section include, when not in a section: %s\n", line); #ifndef BENCH_BUILD log_event ("! ERROR, invalid section include, when not in a section: %s", line); #endif return 1; } *p2 = 0; strlwr(p); if (!strcmp(cfg_database->name, p)) { fprintf(stderr, "ERROR, invalid to load the current section (recursive): %s\n", line); #ifndef BENCH_BUILD log_event ("! ERROR, invalid to load the current section (recursive): %s", line); #endif return 1; } p = strtok(p, ":"); p2 = strtok(NULL, ""); if (!p || !p2) { fprintf(stderr, "ERROR, invalid .include line, can not find this section: %s\n", line); #ifndef BENCH_BUILD log_event("! ERROR, invalid .include line, can not find this section: %s", line); #endif return 1; } *Section = ':'; strnzcpy(&Section[1], p2, 254); if ((newsection = cfg_get_section(p, Section))) { if (newsection->list) { struct cfg_line *pLine = newsection->list->head; while (pLine) { cfg_add_line(pLine->data, number); pLine = pLine->next; } return 0; } else { struct cfg_param *current = newsection->params; while (current) { cfg_add_param(current->name, current->value); current = current->next; } return 0; } } fprintf(stderr, "ERROR, could not find include section: %s%s]\n", line, Section); #ifndef BENCH_BUILD log_event("! ERROR, could not find include section: %s%s]", line, Section); #endif return 1; }
/* * Look up a set in libcfg to find the setnumber. * * ASSUMPTIONS: * - a valid cfg handle * * INPUTS: * cfg - cfg handle * tohost - secondary hostname * tofile - secondary volume * * OUTPUTS: * set number if found, otherwise -1 for an error */ int find_setnumber_in_libcfg(CFGFILE *cfg, char *ctag, char *tohost, char *tofile) { int setnumber; int entries, rc; char *buf, *secondary, *shost; char **entry; char *cnode; int offset = 0; if (cfg == NULL) { #ifdef DEBUG rdc_warn(NULL, "cfg is NULL while looking up set number"); #endif return (-1); } entries = cfg_get_section(cfg, &entry, "sndr"); rc = -1; for (setnumber = 1; setnumber <= entries; setnumber++) { buf = entry[setnumber - 1]; (void) strtok(buf, " "); /* phost */ (void) strtok(NULL, " "); /* primary */ (void) strtok(NULL, " "); /* pbitmap */ shost = strtok(NULL, " "); secondary = strtok(NULL, " "); if (ctag && *ctag) { (void) strtok(NULL, " "); /* sbitmap */ (void) strtok(NULL, " "); /* type */ (void) strtok(NULL, " "); /* mode */ (void) strtok(NULL, " "); /* group */ cnode = strtok(NULL, " "); if (ctag && strcmp(cnode, ctag) != 0) { /* filter this out */ ++offset; continue; } } /* Check secondary volume name first, will get less hits */ if (strcmp(secondary, tofile) != 0) { free(buf); continue; } if (strcmp(shost, tohost) == 0) { free(buf); rc = setnumber - offset; break; } free(buf); } while (setnumber < entries) free(entry[setnumber++]); if (entries) free(entry); return (rc); }