static void cpg_deliver_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
{
	struct ast_event *event;

	if (msg_len < ast_event_minimum_length()) {
		ast_debug(1, "Ignoring event that's too small. %u < %u\n",
			(unsigned int) msg_len,
			(unsigned int) ast_event_minimum_length());
		return;
	}

	if (!ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(msg, AST_EVENT_IE_EID))) {
		/* Don't feed events back in that originated locally. */
		return;
	}

	ast_rwlock_rdlock(&event_types_lock);
	if (!event_types[ast_event_get_type(msg)].subscribe) {
		/* We are not configured to subscribe to these events. */
		ast_rwlock_unlock(&event_types_lock);
		return;
	}
	ast_rwlock_unlock(&event_types_lock);

	if (!(event = ast_malloc(msg_len))) {
		return;
	}

	memcpy(event, msg, msg_len);

	ast_event_queue_and_cache(event);
}
static void cpg_confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		const struct cpg_address *member_list, size_t member_list_entries,
		const struct cpg_address *left_list, size_t left_list_entries,
		const struct cpg_address *joined_list, size_t joined_list_entries)
{
	unsigned int i;

	/* If any new nodes have joined, dump our cache of events we are publishing
	 * that originated from this server. */

	if (!joined_list_entries) {
		return;
	}

	for (i = 0; i < ARRAY_LEN(event_types); i++) {
		struct ast_event_sub *event_sub;

		ast_rwlock_rdlock(&event_types_lock);
		if (!event_types[i].publish) {
			ast_rwlock_unlock(&event_types_lock);
			continue;
		}
		ast_rwlock_unlock(&event_types_lock);

		event_sub = ast_event_subscribe_new(i, ast_event_cb, NULL);
		ast_event_sub_append_ie_raw(event_sub, AST_EVENT_IE_EID,
					&ast_eid_default, sizeof(ast_eid_default));
		ast_event_dump_cache(event_sub);
		ast_event_sub_destroy(event_sub);
	}
}
static void cpg_deliver_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
{
	struct ast_event *event;
	void (*publish_handler)(struct ast_event *) = NULL;
	enum ast_event_type event_type;

	if (msg_len < ast_event_minimum_length()) {
		ast_debug(1, "Ignoring event that's too small. %u < %u\n",
			(unsigned int) msg_len,
			(unsigned int) ast_event_minimum_length());
		return;
	}

	if (!ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(msg, AST_EVENT_IE_EID))) {
		/* Don't feed events back in that originated locally. */
		return;
	}

	event_type = ast_event_get_type(msg);
	if (event_type > AST_EVENT_TOTAL) {
		/* Egads, we don't support this */
		return;
	}

	ast_rwlock_rdlock(&event_types_lock);
	publish_handler = event_types[event_type].publish_to_stasis;
	if (!event_types[event_type].subscribe || !publish_handler) {
		/* We are not configured to subscribe to these events or
		   we have no way to publish it internally. */
		ast_rwlock_unlock(&event_types_lock);
		return;
	}
	ast_rwlock_unlock(&event_types_lock);

	if (!(event = ast_malloc(msg_len))) {
		return;
	}

	memcpy(event, msg, msg_len);

	if (event_type == AST_EVENT_PING) {
		const struct ast_eid *eid;
		char buf[128] = "";

		eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
		ast_eid_to_str(buf, sizeof(buf), (struct ast_eid *) eid);
		ast_log(LOG_NOTICE, "Got event PING from server with EID: '%s'\n", buf);
	}
	ast_debug(5, "Publishing event %s (%u) to stasis\n",
		ast_event_get_type_name(event), event_type);
	publish_handler(event);
}
static void cpg_confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		const struct cpg_address *member_list, size_t member_list_entries,
		const struct cpg_address *left_list, size_t left_list_entries,
		const struct cpg_address *joined_list, size_t joined_list_entries)
{
	unsigned int i;


	for (i = 0; i < left_list_entries; i++) {
		const struct cpg_address *cpg_node = &left_list[i];
		struct corosync_node* node;

		node = ao2_find(nodes, &cpg_node->nodeid, OBJ_UNLINK | OBJ_SEARCH_KEY);
		if (!node) {
			continue;
		}

		publish_cluster_discovery_to_stasis_full(node, 0);
		ao2_ref(node, -1);
	}

	/* If any new nodes have joined, dump our cache of events we are publishing
	 * that originated from this server. */
	if (!joined_list_entries) {
		return;
	}

	for (i = 0; i < ARRAY_LEN(event_types); i++) {
		struct ao2_container *messages;

		ast_rwlock_rdlock(&event_types_lock);
		if (!event_types[i].publish) {
			ast_rwlock_unlock(&event_types_lock);
			continue;
		}

		if (!event_types[i].cache_fn || !event_types[i].message_type_fn) {
			ast_rwlock_unlock(&event_types_lock);
			continue;
		}

		messages = stasis_cache_dump_by_eid(event_types[i].cache_fn(),
			event_types[i].message_type_fn(),
			&ast_eid_default);
		ast_rwlock_unlock(&event_types_lock);

		ao2_callback(messages, OBJ_NODATA, dump_cache_cb, NULL);

		ao2_t_ref(messages, -1, "Dispose of dumped cache");
	}
}
Exemple #5
0
/*! \internal
 * \brief determine if a list of attribute key value pairs are set on a format
 */
static int format_isset_helper(const struct ast_format *format, va_list ap)
{
	int res;
	struct interface_ao2_wrapper *wrapper;
	struct ast_format tmp = {
		.id = format->id,
		.fattr = { { 0, }, },
	};

	if (!(wrapper = find_interface(format))) {
		return -1;
	}

	ast_rwlock_rdlock(&wrapper->wraplock);
	if (!wrapper->interface ||
		!wrapper->interface->format_attr_set ||
		!wrapper->interface->format_attr_cmp) {

		ast_rwlock_unlock(&wrapper->wraplock);
		ao2_ref(wrapper, -1);
		return -1;
	}

	/* if isset is present, use that function, else just build a new
	 * format and use the cmp function */
	if (wrapper->interface->format_attr_isset) {
		res = wrapper->interface->format_attr_isset(&format->fattr, ap);
	} else {
		wrapper->interface->format_attr_set(&tmp.fattr, ap);
		/* use our tmp structure to tell if the attributes are set or not */
		res = wrapper->interface->format_attr_cmp(&tmp.fattr, &format->fattr);
		res = (res == AST_FORMAT_CMP_NOT_EQUAL) ? -1 : 0;
	}

	ast_rwlock_unlock(&wrapper->wraplock);
	ao2_ref(wrapper, -1);

	return res;
}

int ast_format_isset(const struct ast_format *format, ... )
{
	va_list ap;
	int res;

	va_start(ap, format);
	res = format_isset_helper(format, ap);
	va_end(ap);
	return res;
}
static int handle_show_http(int fd, int argc, char *argv[])
{
	struct ast_http_uri *urih;

	if (argc != 3)
		return RESULT_SHOWUSAGE;

	ast_cli(fd, "HTTP Server Status:\n");
	ast_cli(fd, "Prefix: %s\n", prefix);
	if (oldsin.sin_family)
		ast_cli(fd, "Server Enabled and Bound to %s:%d\n\n",
			ast_inet_ntoa(oldsin.sin_addr),
			ntohs(oldsin.sin_port));
	else
		ast_cli(fd, "Server Disabled\n\n");
	ast_cli(fd, "Enabled URI's:\n");
	ast_rwlock_rdlock(&uris_lock);
	urih = uris;
	while(urih){
		ast_cli(fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
		urih = urih->next;
	}
	if (!uris)
		ast_cli(fd, "None.\n");
	ast_rwlock_unlock(&uris_lock);

	return RESULT_SUCCESS;
}
Exemple #7
0
int ast_adsi_channel_restore(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->channel_restore) {
		res = installed_funcs->channel_restore(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #8
0
int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->print) {
		res = installed_funcs->print(chan, lines, align, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #9
0
int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->get_cpeinfo) {
		res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #10
0
int ast_adsi_end_download(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->end_download) {
		res = installed_funcs->end_download(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #11
0
int ast_adsi_query_cpeinfo(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->query_cpeinfo) {
		res = installed_funcs->query_cpeinfo(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #12
0
int ast_adsi_data_mode(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->data_mode) {
		res = installed_funcs->data_mode(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #13
0
int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->download_connect) {
		res = installed_funcs->download_connect(buf, service, fdn, sec, ver);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #14
0
int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->transmit_message) {
		res = installed_funcs->transmit_message(chan, msg, msglen, msgtype);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #15
0
int ast_adsi_set_line(unsigned char *buf, int page, int line)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->set_line) {
		res = installed_funcs->set_line(buf, page, line);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #16
0
int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->load_soft_key) {
		res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #17
0
int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->display) {
		res = installed_funcs->display(buf, page, line, just, wrap, col1, col2);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #18
0
int ast_adsi_voice_mode(unsigned char *buf, int when)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->voice_mode) {
		res = installed_funcs->voice_mode(buf, when);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #19
0
int ast_adsi_clear_screen(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->clear_screen) {
		res = installed_funcs->clear_screen(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #20
0
int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->load_session) {
		res = installed_funcs->load_session(chan, app, ver, data);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #21
0
int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->begin_download) {
		res = installed_funcs->begin_download(chan, service, fdn, sec, version);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #22
0
int ast_adsi_unload_session(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->unload_session) {
		res = installed_funcs->unload_session(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #23
0
int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->connect_session) {
		res = installed_funcs->connect_session(buf, fdn, ver);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #24
0
int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->get_cpeid) {
		res = installed_funcs->get_cpeid(chan, cpeid, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #25
0
int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->input_format) {
		res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #26
0
int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->set_keys) {
		res = installed_funcs->set_keys(buf, keys);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #27
0
int ast_adsi_download_disconnect(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->download_disconnect) {
		res = installed_funcs->download_disconnect(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #28
0
int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->input_control) {
		res = installed_funcs->input_control(buf, page, line, display, format, just);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #29
0
int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->read_encoded_dtmf) {
		res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}
Exemple #30
0
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);
}