int cfg_parse_bool_opt(void* param, cfg_parser_t* st, unsigned int flags) { int ret; if (cfg_eat_equal(st, flags)) return -1; ret = cfg_parse_bool(param, st, CFG_EXTENDED_ALPHA | flags); if (ret > 0) { ERR("%s:%d:%d: Option value missing\n", st->file, st->line, st->col); } else if (ret < 0) return ret; if (cfg_eat_eol(st, flags)) return -1; return 0; }
int cfg_parse_section(void* param, cfg_parser_t* st, unsigned int flags) { cfg_token_t t; int ret; ret = cfg_parse_str(param, st, flags); if (ret < 0) return ret; if (ret > 0) { ERR("%s:%d:%d: Section name missing.\n", st->file, st->line, st->col); return ret; } ret = cfg_get_token(&t, st, flags); if (ret < 0) goto error; if (ret > 0) { ERR("%s:%d:%d: Closing ']' missing\n", st->file, st->line, st->col); goto error; } if (t.type != ']') { ERR("%s:%d:%d: Syntax error, ']' expected\n", st->file, t.start.line, t.start.col); goto error; } if (cfg_eat_eol(st, flags)) goto error; return 0; error: if (param && ((str*)param)->s) { if (flags & CFG_STR_PKGMEM) { pkg_free(((str*)param)->s); ((str*)param)->s = NULL; } else if (flags & CFG_STR_SHMMEM) { shm_free(((str*)param)->s); ((str*)param)->s = NULL; } else if (flags & CFG_STR_MALLOC) { free(((str*)param)->s); ((str*)param)->s = NULL; } } return -1; }
static int parse_domain(void* param, cfg_parser_t* st, unsigned int flags) { cfg_token_t t; int ret; cfg_option_t* opt; int type; struct ip_addr ip; unsigned int port; memset(&ip, 0, sizeof(struct ip_addr)); ret = cfg_get_token(&t, st, 0); if (ret < 0) return -1; if (ret > 0) { ERR("%s:%d:%d: TLS domain type missing\n", st->file, st->line, st->col); return -1; } if (t.type != CFG_TOKEN_ALPHA || ((opt = cfg_lookup_token(domain_types, &t.val)) == NULL)) { ERR("%s:%d:%d: Invalid TLS domain type %d:'%.*s'\n", st->file, t.start.line, t.start.col, t.type, STR_FMT(&t.val)); return -1; } ret = cfg_get_token(&t, st, 0); if (ret < 0) return -1; if (ret > 0) { ERR("%s:%d:%d: TLS domain IP address missing\n", st->file, st->line, st->col); return -1; } if (t.type != ':') { ERR("%s:%d:%d: Syntax error, ':' expected\n", st->file, t.start.line, t.start.col); return -1; } port = 0; if (parse_hostport(&type, &ip, &port, &t, st) < 0) return -1; ret = cfg_get_token(&t, st, 0); if (ret < 0) return -1; if (ret > 0) { ERR("%s:%d:%d: Closing ']' missing\n", st->file, st->line, st->col); return -1; } if (t.type != ']') { ERR("%s:%d:%d: Syntax error, ']' expected\n", st->file, t.start.line, t.start.col); return -1; } if (cfg_eat_eol(st, flags)) return -1; if ((domain = tls_new_domain(opt->val | type, &ip, port)) == NULL) { ERR("%s:%d: Cannot create TLS domain structure\n", st->file, st->line); return -1; } ret = tls_add_domain(cfg, domain); if (ret < 0) { ERR("%s:%d: Error while creating TLS domain structure\n", st->file, st->line); tls_free_domain(domain); return -1; } else if (ret == 1) { ERR("%s:%d: Duplicate TLS domain (appears earlier in the config file)\n", st->file, st->line); tls_free_domain(domain); return -1; } update_opt_variables(); cfg_set_options(st, options); return 0; }