int override_config_tree_from_string(struct cmd_context *cmd, const char *config_settings) { struct dm_config_tree *cft_new; struct config_source *cs = dm_config_get_custom(cmd->cft); /* * Follow this sequence: * CONFIG_STRING -> CONFIG_PROFILE -> CONFIG_FILE/CONFIG_MERGED_FILES */ if (cs->type == CONFIG_STRING) { log_error(INTERNAL_ERROR "override_config_tree_from_string: " "config cascade already contains a string config."); return 0; } if (!(cft_new = dm_config_from_string(config_settings))) { log_error("Failed to set overridden configuration entries."); return 0; } if (!(cs = dm_pool_zalloc(cft_new->mem, sizeof(struct config_source)))) { log_error("Failed to allocate config source."); dm_config_destroy(cft_new); return 0; } cs->type = CONFIG_STRING; dm_config_set_custom(cft_new, cs); cmd->cft = dm_config_insert_cascaded_tree(cft_new, cmd->cft); return 1; }
/* * 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; }
/* * 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; }