int svn_config_enumerate(svn_config_t *cfg, const char *section, svn_config_enumerator_t callback, void *baton) { cfg_section_t *sec; apr_hash_index_t *opt_ndx; int count; apr_pool_t *subpool; find_option(cfg, section, NULL, &sec); if (sec == NULL) return 0; subpool = svn_pool_create(cfg->pool); count = 0; for (opt_ndx = apr_hash_first(subpool, sec->options); opt_ndx != NULL; opt_ndx = apr_hash_next(opt_ndx)) { void *opt_ptr; cfg_option_t *opt; const char *temp_value; apr_hash_this(opt_ndx, NULL, NULL, &opt_ptr); opt = opt_ptr; ++count; make_string_from_option(&temp_value, cfg, sec, opt, NULL); if (!callback(opt->name, temp_value, baton)) break; } svn_pool_destroy(subpool); return count; }
void svn_config_get(svn_config_t *cfg, const char **valuep, const char *section, const char *option, const char *default_value) { *valuep = default_value; if (cfg) { cfg_section_t *sec; cfg_option_t *opt = find_option(cfg, section, option, &sec); if (opt != NULL) { make_string_from_option(valuep, cfg, sec, opt, NULL); } else /* before attempting to expand an option, check for the placeholder. * If there is none, there is no point in calling expand_option_value. */ if (default_value && strchr(default_value, '%')) { apr_pool_t *tmp_pool = svn_pool_create(cfg->pool); const char *x_default; expand_option_value(cfg, sec, default_value, &x_default, tmp_pool); if (x_default) { svn_stringbuf_set(cfg->tmp_value, x_default); *valuep = cfg->tmp_value->data; } svn_pool_destroy(tmp_pool); } } }
void svn_config_get(svn_config_t *cfg, const char **valuep, const char *section, const char *option, const char *default_value) { if (cfg) { cfg_section_t *sec; cfg_option_t *opt = find_option(cfg, section, option, &sec); if (opt != NULL) { make_string_from_option(valuep, cfg, sec, opt, NULL); } else { apr_pool_t *tmp_pool = svn_pool_create(cfg->x_pool); const char *x_default; expand_option_value(cfg, sec, default_value, &x_default, tmp_pool); if (x_default) { svn_stringbuf_set(cfg->tmp_value, x_default); *valuep = cfg->tmp_value->data; } else *valuep = default_value; svn_pool_destroy(tmp_pool); } } else { *valuep = default_value; } }
/* Expand OPT_VALUE (which may be NULL) in SECTION into *OPT_X_VALUEP. If no variable replacements are done, set *OPT_X_VALUEP to NULL. Allocate from X_POOL. */ static void expand_option_value(svn_config_t *cfg, cfg_section_t *section, const char *opt_value, const char **opt_x_valuep, apr_pool_t *x_pool) { svn_stringbuf_t *buf = NULL; const char *parse_from = opt_value; const char *copy_from = parse_from; const char *name_start, *name_end; while (parse_from != NULL && *parse_from != '\0' && (name_start = strstr(parse_from, FMT_START)) != NULL) { name_start += FMT_START_LEN; if (*name_start == '\0') /* FMT_START at end of opt_value. */ break; name_end = strstr(name_start, FMT_END); if (name_end != NULL) { cfg_option_t *x_opt; apr_size_t len = name_end - name_start; char *name = apr_pstrmemdup(x_pool, name_start, len); x_opt = find_option(cfg, section->name, name, NULL); if (x_opt != NULL) { const char *cstring; /* Pass back the sub-pool originally provided by make_string_from_option() as an indication of when it should terminate. */ make_string_from_option(&cstring, cfg, section, x_opt, x_pool); /* Append the plain text preceding the expansion. */ len = name_start - FMT_START_LEN - copy_from; if (buf == NULL) { buf = svn_stringbuf_ncreate(copy_from, len, x_pool); cfg->x_values = TRUE; } else svn_stringbuf_appendbytes(buf, copy_from, len); /* Append the expansion and adjust parse pointers. */ svn_stringbuf_appendcstr(buf, cstring); parse_from = name_end + FMT_END_LEN; copy_from = parse_from; } else /* Though ConfigParser considers the failure to resolve the requested expansion an exception condition, we consider it to be plain text, and look for the start of the next one. */ parse_from = name_end + FMT_END_LEN; } else /* Though ConfigParser treats unterminated format specifiers as an exception condition, we consider them to be plain text. The fact that there are no more format specifier endings means we're done parsing. */ parse_from = NULL; } if (buf != NULL) { /* Copy the remainder of the plain text. */ svn_stringbuf_appendcstr(buf, copy_from); *opt_x_valuep = buf->data; } else *opt_x_valuep = NULL; }