void iprange_fn(const char *token, char *value, void *setting, FILE *f) { struct s_ip **ip = setting; if (value) { if(strlen(value) == 0) { clear_sip(ip); } else { chk_iprange(value, ip); } return; } value = mk_t_iprange(*ip); if (strlen(value) > 0 || cfg.http_full_cfg) fprintf_conf(f, token, "%s\n", value); free_mk_t(value); }
int32_t init_config(void) { FILE *fp; if(config_enabled(WEBIF)) { fp = open_config_file(cs_conf); } else { fp = open_config_file_or_die(cs_conf); } const struct config_sections *cur_section = oscam_conf; // Global char *token; config_sections_set_defaults(oscam_conf, &cfg); if(!fp) { // no oscam.conf but webif is included in build, set it up for lan access and tweak defaults #ifdef WEBIF cfg.http_port = DEFAULT_HTTP_PORT; chk_iprange(cs_strdup(DEFAULT_HTTP_ALLOW), &cfg.http_allowed); #endif NULLFREE(cfg.logfile); cfg.logtostdout = 1; #ifdef HAVE_DVBAPI cfg.dvbapi_enabled = 1; #endif return 0; } if(!cs_malloc(&token, MAXLINESIZE)) { return 1; } int line = 0; int valid_section = 1; while(fgets(token, MAXLINESIZE, fp)) { ++line; int len = strlen(trim(token)); if(len < 3) // a=b or [a] are at least 3 chars { continue; } if(token[0] == '#') // Skip comments { continue; } if(token[0] == '[' && token[len - 1] == ']') { token[len - 1] = '\0'; valid_section = 0; const struct config_sections *newconf = config_find_section(oscam_conf, token + 1); if(config_section_is_active(newconf) && cur_section) { config_list_apply_fixups(cur_section->config, &cfg); cur_section = newconf; valid_section = 1; } if(!newconf) { fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n", cs_conf, line, token + 1); continue; } if(!config_section_is_active(newconf)) { fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n", cs_conf, line, newconf->section); } continue; } if(!valid_section) { continue; } char *value = strchr(token, '='); if(!value) // No = found, well go on { continue; } *value++ = '\0'; char *tvalue = trim(value); char *ttoken = trim(strtolower(token)); if(cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg)) { fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n", cs_conf, line, cur_section->section, ttoken, tvalue); } } free(token); fclose(fp); if(cur_section) { config_list_apply_fixups(cur_section->config, &cfg); } return 0; }