Exemplo n.º 1
0
Arquivo: adsi.c Projeto: GGGO/asterisk
void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
{
	if (funcs && funcs->version < current_adsi_version) {
		ast_log(LOG_WARNING, "Cannot install ADSI function pointers due to version mismatch."
				"Ours: %d, Theirs: %u\n", current_adsi_version, funcs->version);
		return;
	}

	ast_rwlock_wrlock(&func_lock);
	installed_funcs = funcs;
	ast_rwlock_unlock(&func_lock);
}
Exemplo n.º 2
0
int ast_http_uri_link(struct ast_http_uri *urih)
{
	struct ast_http_uri *prev;

	ast_rwlock_wrlock(&uris_lock);
	prev = uris;
	if (!uris || strlen(uris->uri) <= strlen(urih->uri)) {
		urih->next = uris;
		uris = urih;
	} else {
		while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri)))
			prev = prev->next;
		/* Insert it here */
		urih->next = prev->next;
		prev->next = urih;
	}
	ast_rwlock_unlock(&uris_lock);

	return 0;
}	
Exemplo n.º 3
0
void ast_http_uri_unlink(struct ast_http_uri *urih)
{
	struct ast_http_uri *prev;

	ast_rwlock_wrlock(&uris_lock);
	if (!uris) {
		ast_rwlock_unlock(&uris_lock);
		return;
	}
	prev = uris;
	if (uris == urih) {
		uris = uris->next;
	}
	while(prev->next) {
		if (prev->next == urih) {
			prev->next = urih->next;
			break;
		}
		prev = prev->next;
	}
	ast_rwlock_unlock(&uris_lock);
}
Exemplo n.º 4
0
static int load_config(int reload)
{
	char *cat = NULL;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
	int newenablecdr = 0;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
		return -1;
	}

	if (!cfg) {
		/* Standard configuration */
		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
		if (enablecdr)
			ast_cdr_unregister(name);
		enablecdr = 0;
		return -1;
	}

	if (reload) {
		ast_rwlock_wrlock(&customfields_lock);
	}

	if (reload && customfields) {
		ast_free(customfields);
		customfields = NULL;
	}

	while ( (cat = ast_category_browse(cfg, cat)) ) {
		if (!strcasecmp(cat, "general")) {
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (!strcasecmp(v->name, "enabled"))
					newenablecdr = ast_true(v->value);

				v = v->next;
			}
		} else if (!strcasecmp(cat, "mappings")) {
			customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) {
						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
					} else {
						ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
						break;
					}

				}
				v = v->next;
			}
		}
	}

	if (reload) {
		ast_rwlock_unlock(&customfields_lock);
	}

	ast_config_destroy(cfg);

	if (enablecdr && !newenablecdr)
		ast_cdr_unregister(name);
	else if (!enablecdr && newenablecdr)
		ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
	enablecdr = newenablecdr;

	return 0;
}
Exemplo n.º 5
0
static int load_config(int reload) {
	char *cat = NULL;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = {reload ? CONFIG_FLAG_FILEUNCHANGED : 0};
	int newenablecdr = 0;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
		return -1;
	}

	if (!cfg) {
		/* Standard configuration */
		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
		if (enablecdr) {
			ast_cdr_backend_suspend(name);
		}
		enablecdr = 0;
		return -1;
	}

	if (reload) {
		ast_rwlock_wrlock(&config_lock);
		ast_free(bs_host);
		ast_free(bs_tube);
	}

	/* Bootstrap the default configuration */
	bs_host = ast_strdup(DEFAULT_BEANSTALK_HOST);
	bs_port = DEFAULT_BEANSTALK_PORT;
	bs_tube = ast_strdup(DEFAULT_BEANSTALK_TUBE);
	priority = BEANSTALK_JOB_PRIORITY;

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

				if (!strcasecmp(v->name, "enabled")) {
					newenablecdr = ast_true(v->value);
				} else if (!strcasecmp(v->name, "host")) {
					ast_free(bs_host);
					bs_host = ast_strdup(v->value);
				} else if (!strcasecmp(v->name, "port")) {
					bs_port = atoi(v->value);
				} else if (!strcasecmp(v->name, "tube")) {
					ast_free(bs_tube);
					bs_tube = ast_strdup(v->value);
				} else if (!strcasecmp(v->name, "priority")) {
					priority = atoi(v->value);
				}
				v = v->next;

			}
		}
	}

	if (reload) {
		ast_rwlock_unlock(&config_lock);
	}

	ast_config_destroy(cfg);

	if (!newenablecdr) {
		ast_cdr_backend_suspend(name);
	} else if (newenablecdr) {
		ast_cdr_backend_unsuspend(name);
		ast_log(LOG_NOTICE, "Added beanstalkd server %s at port %d with tube %s", bs_host, bs_port, bs_tube);
	}
	enablecdr = newenablecdr;

	return 0;
}
Exemplo n.º 6
0
int ast_heap_wrlock(struct ast_heap *h)
{
	return ast_rwlock_wrlock(&h->lock);
}