示例#1
0
static int __ast_http_post_load(int reload)
{
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	cfg = ast_config_load2("http.conf", "http", config_flags);
	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
		return 0;
	}

	if (reload) {
		ast_http_uri_unlink_all_with_key(__FILE__);
	}

	if (cfg) {
		for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
			if (!strcasecmp(v->name, "prefix")) {
				ast_copy_string(prefix, v->value, sizeof(prefix));
				if (prefix[strlen(prefix)] == '/') {
					prefix[strlen(prefix)] = '\0';
				}
			}
		}

		for (v = ast_variable_browse(cfg, "post_mappings"); v; v = v->next) {
			struct ast_http_uri *urih;
			struct ast_str *ds;

			if (!(urih = ast_calloc(sizeof(*urih), 1))) {
				ast_config_destroy(cfg);
				return -1;
			}

			if (!(ds = ast_str_create(32))) {
				ast_free(urih);
				ast_config_destroy(cfg);
				return -1;
			}

			urih->description = ast_strdup("HTTP POST mapping");
			urih->uri = ast_strdup(v->name);
			ast_str_set(&ds, 0, "%s", v->value);
			urih->data = ds;
			urih->has_subtree = 0;
			urih->supports_get = 0;
			urih->supports_post = 1;
			urih->callback = http_post_callback;
			urih->key = __FILE__;
			urih->mallocd = urih->dmallocd = 1;

			ast_http_uri_link(urih);
		}

		ast_config_destroy(cfg);
	}
	return 0;
}
示例#2
0
文件: cel.c 项目: RoyalG41/Asterisk
static int do_reload(void)
{
	struct ast_config *config;
	const char *enabled_value;
	const char *val;
	int res = 0;
	struct ast_flags config_flags = { 0, };
	const char *s;

	ast_mutex_lock(&reload_lock);

	/* Reset all settings before reloading configuration */
	cel_enabled = CEL_ENALBED_DEFAULT;
	eventset = CEL_DEFAULT_EVENTS;
	*cel_dateformat = '\0';
	ao2_callback(appset, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);

	config = ast_config_load2("cel.conf", "cel", config_flags);

	if (config == CONFIG_STATUS_FILEMISSING) {
		config = NULL;
		goto return_cleanup;
	}

	if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
		cel_enabled = ast_true(enabled_value);
	}

	if (!cel_enabled) {
		goto return_cleanup;
	}

	/* get the date format for logging */
	if ((s = ast_variable_retrieve(config, "general", "dateformat"))) {
		ast_copy_string(cel_dateformat, s, sizeof(cel_dateformat));
	}

	if ((val = ast_variable_retrieve(config, "general", "events"))) {
		parse_events(val);
	}

	if ((val = ast_variable_retrieve(config, "general", "apps"))) {
		parse_apps(val);
	}

return_cleanup:
	ast_verb(3, "CEL logging %sabled.\n", cel_enabled ? "en" : "dis");

	ast_mutex_unlock(&reload_lock);

	if (config) {
		ast_config_destroy(config);
	}

	return res;
}
示例#3
0
static int load_config(int startup)
{
	struct ast_flags config_flags = { 0, };
	struct ast_config *cfg;
	struct ast_variable *v;

	if (!startup) {
		ast_set_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
	}

	cfg = ast_config_load2(stun_conf_file, "res_stun_monitor", config_flags);
	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_WARNING, "Unable to load config %s\n", stun_conf_file);
		return -1;
	}
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	/* clean up any previous open socket */
	stun_close_sock();
	args.stun_poll_failed_gripe = 0;

	/* set defaults */
	args.monitor_enabled = 0;
	args.refresh = DEFAULT_MONITOR_REFRESH;

	for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
		if (!strcasecmp(v->name, "stunaddr")) {
			if (setup_stunaddr(v->value)) {
				ast_log(LOG_WARNING, "Invalid STUN server address: %s at line %d\n",
					v->value, v->lineno);
			}
		} else if (!strcasecmp(v->name, "stunrefresh")) {
			if ((sscanf(v->value, "%30u", &args.refresh) != 1) || !args.refresh) {
				ast_log(LOG_WARNING, "Invalid stunrefresh value '%s', must be an integer > 0 at line %d\n", v->value, v->lineno);
				args.refresh = DEFAULT_MONITOR_REFRESH;
			}
		} else {
			ast_log(LOG_WARNING, "Invalid config option %s at line %d\n",
				v->value, v->lineno);
		}
	}

	ast_config_destroy(cfg);

	return 0;
}
示例#4
0
/*! \brief Initialize the ENUM support subsystem */
static int private_enum_init(int reload)
{
	struct ast_config *cfg;
	const char *string;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	if ((cfg = ast_config_load2("enum.conf", "enum", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
		return 0;
	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
		return 0;
	}

	/* Destroy existing list */
	ast_mutex_lock(&enumlock);
	if (cfg) {
		if ((string = ast_variable_retrieve(cfg, "ienum", "branchlabel"))) {
			ast_copy_string(ienum_branchlabel, string, sizeof(ienum_branchlabel));
		}

		if ((string = ast_variable_retrieve(cfg, "ienum", "ebl_alg"))) {
			ebl_alg = ENUMLOOKUP_BLR_CC; /* default */

			if (!strcasecmp(string, "txt"))
				ebl_alg = ENUMLOOKUP_BLR_TXT;
			else if (!strcasecmp(string, "ebl"))
				ebl_alg = ENUMLOOKUP_BLR_EBL;
			else if (!strcasecmp(string, "cc"))
				ebl_alg = ENUMLOOKUP_BLR_CC;
			else
				ast_log(LOG_WARNING, "No valid parameter for ienum/ebl_alg.\n");
		}
		ast_config_destroy(cfg);
	}
	ast_mutex_unlock(&enumlock);
	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Enum\r\nStatus: Enabled\r\nMessage: ENUM reload Requested\r\n");
	return 0;
}
int load_mrcp_config(const char *filename, const char *who_asked)
{
	const char *cat = NULL;
	struct ast_variable *var;
	const char *value = NULL;

#if AST_VERSION_AT_LEAST(1,6,0)
	struct ast_flags config_flags = { 0 };
	struct ast_config *cfg = ast_config_load2(filename, who_asked, config_flags);
#else
	struct ast_config *cfg = ast_config_load(filename);
#endif
	if (!cfg) {
		ast_log(LOG_WARNING, "No such configuration file %s\n", filename);
		return -1;
	}
#if AST_VERSION_AT_LEAST(1,6,2)
	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file %s is in an invalid format\n", filename);
		return -1;
	}
#endif

	globals_clear();
	globals_default();

	if ((value = ast_variable_retrieve(cfg, "general", "default-tts-profile")) != NULL) {
		ast_log(LOG_DEBUG, "general.default-tts-profile=%s\n",  value);
		globals.unimrcp_default_synth_profile = apr_pstrdup(globals.pool, value);
	} else {
		ast_log(LOG_ERROR, "Unable to load genreal.default-tts-profile from config file, aborting\n");
		ast_config_destroy(cfg);
		return -1;
	}
	if ((value = ast_variable_retrieve(cfg, "general", "default-asr-profile")) != NULL) {
		ast_log(LOG_DEBUG, "general.default-asr-profile=%s\n",  value);
		globals.unimrcp_default_recog_profile = apr_pstrdup(globals.pool, value);
	} else {
		ast_log(LOG_ERROR, "Unable to load genreal.default-asr-profile from config file, aborting\n");
		ast_config_destroy(cfg);
		return -1;
	}
	if ((value = ast_variable_retrieve(cfg, "general", "log-level")) != NULL) {
		ast_log(LOG_DEBUG, "general.log-level=%s\n",  value);
		globals.unimrcp_log_level = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "max-connection-count")) != NULL) {
		ast_log(LOG_DEBUG, "general.max-connection-count=%s\n",  value);
		globals.unimrcp_max_connection_count = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "offer-new-connection")) != NULL) {
		ast_log(LOG_DEBUG, "general.offer-new-connection=%s\n",  value);
		globals.unimrcp_offer_new_connection = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "rx-buffer-size")) != NULL) {
		ast_log(LOG_DEBUG, "general.rx-buffer-size=%s\n",  value);
		globals.unimrcp_rx_buffer_size = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "tx-buffer-size")) != NULL) {
		ast_log(LOG_DEBUG, "general.tx-buffer-size=%s\n",  value);
		globals.unimrcp_tx_buffer_size = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "request-timeout")) != NULL) {
		ast_log(LOG_DEBUG, "general.request-timeout=%s\n",  value);
		globals.unimrcp_request_timeout = apr_pstrdup(globals.pool, value);
	}

	while ((cat = ast_category_browse(cfg, cat)) != NULL) {
		if (strcasecmp(cat, "general") != 0) {
			if ((value = ast_variable_retrieve(cfg, cat, "version")) != NULL) {
				ast_mrcp_profile_t *mod_profile = NULL;

				if (profile_create(&mod_profile, cat, value, globals.pool) == 0) {
					apr_hash_set(globals.profiles, apr_pstrdup(globals.pool, mod_profile->name), APR_HASH_KEY_STRING, mod_profile);

					for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
						ast_log(LOG_DEBUG, "%s.%s=%s\n", cat, var->name, var->value);
						apr_hash_set(mod_profile->cfg, apr_pstrdup(globals.pool, var->name), APR_HASH_KEY_STRING, apr_pstrdup(globals.pool, var->value));
					}
				} else
					ast_log(LOG_WARNING, "Unable to create a profile for %s\n", cat);
			} else
				ast_log(LOG_WARNING, "Category %s does not have a version variable defined\n", cat);
		}
	}

	ast_config_destroy(cfg);

	return 0;
}
示例#6
0
int misdn_cfg_init(int this_max_ports, int reload)
{
	char config[] = "misdn.conf";
	char *cat, *p;
	int i;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	if (!(cfg = ast_config_load2(config, "chan_misdn", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_WARNING, "missing or invalid file: misdn.conf\n");
		return -1;
	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
		return 0;

	ast_mutex_init(&config_mutex);

	/* Copy the default jb config over global_jbconf */
	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));

	misdn_cfg_lock();

	if (this_max_ports) {
		/* this is the first run */
		max_ports = this_max_ports;
		map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
		if (_enum_array_map())
			return -1;
		p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
						   + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
		port_cfg = (union misdn_cfg_pt **)p;
		p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
		for (i = 0; i <= max_ports; ++i) {
			port_cfg[i] = (union misdn_cfg_pt *)p;
			p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
		}
		general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		ptp = ast_calloc(max_ports + 1, sizeof(int));
	}
	else {
		/* misdn reload */
		_free_port_cfg();
		_free_general_cfg();
		memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
		memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		memset(ptp, 0, sizeof(int) * (max_ports + 1));
	}

	cat = ast_category_browse(cfg, NULL);

	while(cat) {
		v = ast_variable_browse(cfg, cat);
		if (!strcasecmp(cat, "general")) {
			_build_general_config(v);
		} else {
			_build_port_config(v, cat);
		}
		cat = ast_category_browse(cfg, cat);
	}

	_fill_defaults();

	misdn_cfg_unlock();
	ast_config_destroy(cfg);

	return 0;
}