ni_config_t * ni_config_parse(const char *filename, ni_init_appdata_callback_t *cb, void *appdata) { ni_config_t *conf; conf = ni_config_new(); if (!__ni_config_parse(conf, filename, cb, appdata)) { ni_config_free(conf); return NULL; } return conf; }
int ni_init_ex(const char *appname, ni_init_appdata_callback_t *cb, void *appdata) { int explicit_config = 1; if (ni_global.initialized) { ni_error("ni_init called twice"); return -1; } if (__ni_init_gcrypt() < 0) return -1; if (ni_global.config_path == NULL) { if (appname == NULL) { /* Backward compatible - for now. * The server will load config.xml */ appname = "config"; } if (asprintf(&ni_global.config_path, "%s/%s.xml", ni_get_global_config_dir(), appname) < 0) { ni_global.config_path = NULL; return -1; } /* If the application-specific config file does not exist, fall * back to common.xml */ if (!ni_file_exists(ni_global.config_path)) { ni_string_free(&ni_global.config_path); if (asprintf(&ni_global.config_path, "%s/common.xml", ni_get_global_config_dir()) < 0) { ni_global.config_path = NULL; return -1; } } explicit_config = 0; } if (ni_file_exists(ni_global.config_path)) { ni_global.config = ni_config_parse(ni_global.config_path, cb, appdata); if (!ni_global.config) { ni_error("Unable to parse netinfo configuration file"); return -1; } } else { if (explicit_config) { ni_error("Configuration file %s does not exist", ni_global.config_path); return -1; } /* Create empty default configuration */ ni_global.config = ni_config_new(); } /* Our socket code relies on us ignoring this */ signal(SIGPIPE, SIG_IGN); ni_global.initialized = 1; return 0; }