/* * public interface */ struct dm_config_tree *config_file_open(const char *filename, int keep_open) { struct dm_config_tree *cft = dm_config_create(); struct config_file *cf; if (!cft) return NULL; cf = dm_pool_zalloc(cft->mem, sizeof(struct config_file)); if (!cf) goto fail; cf->timestamp = 0; cf->exists = 0; cf->keep_open = keep_open; dm_config_set_custom(cft, cf); if (filename && !(cf->filename = dm_pool_strdup(cft->mem, filename))) { log_error("Failed to duplicate filename."); goto fail; } return cft; fail: dm_config_destroy(cft); return NULL; }
struct dm_config_tree *dm_config_from_string(const char *config_settings) { struct dm_config_tree *cft; if (!(cft = dm_config_create())) return_NULL; if (!dm_config_parse(cft, config_settings, config_settings + strlen(config_settings))) { dm_config_destroy(cft); return_NULL; } return cft; }
struct dm_config_tree *dm_config_flatten(struct dm_config_tree *cft) { struct dm_config_tree *res = dm_config_create(), *done = NULL, *current = NULL; if (!res) return_NULL; while (done != cft) { current = cft; while (current->cascade != done) current = current->cascade; _enumerate("", current->root, _override_path, res); done = current; } return res; }
/* * public interface */ struct dm_config_tree *config_open(config_source_t source, const char *filename, int keep_open) { struct dm_config_tree *cft = dm_config_create(); struct config_source *cs; struct config_file *cf; if (!cft) return NULL; if (!(cs = dm_pool_zalloc(cft->mem, sizeof(struct config_source)))) { log_error("Failed to allocate config source."); goto fail; } if ((source == CONFIG_FILE) || (source == CONFIG_PROFILE)) { if (!(cf = dm_pool_zalloc(cft->mem, sizeof(struct config_file)))) { log_error("Failed to allocate config file."); goto fail; } cf->keep_open = keep_open; if (filename && !(cf->filename = dm_pool_strdup(cft->mem, filename))) { log_error("Failed to duplicate filename."); goto fail; } cs->source.file = cf; } cs->type = source; dm_config_set_custom(cft, cs); return cft; fail: dm_config_destroy(cft); return NULL; }