static int send_bridge_info_item_cb(void *obj, void *arg, void *data, int flags)
{
	char *uniqueid = obj;
	struct mansession *s = arg;
	char *id_text = data;
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	struct ast_channel_snapshot *snapshot;
	RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
	msg = stasis_cache_get(ast_channel_cache(),
		ast_channel_snapshot_type(), uniqueid);

	if (!msg) {
		return 0;
	}

	snapshot = stasis_message_data(msg);
	if (snapshot->tech_properties & AST_CHAN_TP_INTERNAL) {
		return 0;
	}

	channel_text = ast_manager_build_channel_state_string(snapshot);
	if (!channel_text) {
		return 0;
	}

	astman_append(s,
		"Event: BridgeInfoChannel\r\n"
		"%s"
		"%s"
		"\r\n",
		ast_str_buffer(channel_text),
		id_text);
	return 0;
}
Example #2
0
struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
	const char *name)
{
	RAII_VAR(char *, id, NULL, ast_free);
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	struct ast_endpoint_snapshot *snapshot;

	if (ast_strlen_zero(name)) {
		ast_asprintf(&id, "%s", tech);
	} else {
		ast_asprintf(&id, "%s/%s", tech, name);
	}
	if (!id) {
		return NULL;
	}
	ast_tech_to_upper(id);

	msg = stasis_cache_get(ast_endpoint_cache(),
		ast_endpoint_snapshot_type(), id);
	if (!msg) {
		return NULL;
	}

	snapshot = stasis_message_data(msg);
	ast_assert(snapshot != NULL);

	ao2_ref(snapshot, +1);
	return snapshot;
}
void ast_ari_channels_get(struct ast_variable *headers,
	struct ast_ari_channels_get_args *args,
	struct ast_ari_response *response)
{
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	struct stasis_cache *cache;
	struct ast_channel_snapshot *snapshot;

	cache = ast_channel_cache();
	if (!cache) {
		ast_ari_response_error(
			response, 500, "Internal Server Error",
			"Message bus not initialized");
		return;
	}

	msg = stasis_cache_get(cache, ast_channel_snapshot_type(),
				   args->channel_id);
	if (!msg) {
		ast_ari_response_error(
			response, 404, "Not Found",
			"Channel not found");
		return;
	}

	snapshot = stasis_message_data(msg);
	ast_assert(snapshot != NULL);

	ast_ari_response_ok(response,
				ast_channel_snapshot_to_json(snapshot, NULL));
}
Example #4
0
static int manager_bridge_info(struct mansession *s, const struct message *m)
{
	const char *id = astman_get_header(m, "ActionID");
	const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
	RAII_VAR(struct ast_str *, id_text, ast_str_create(128), ast_free);
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	RAII_VAR(struct ast_str *, bridge_info, NULL, ast_free);
	struct ast_bridge_snapshot *snapshot;
	struct bridge_list_data list_data;

	if (!id_text) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	if (ast_strlen_zero(bridge_uniqueid)) {
		astman_send_error(s, m, "BridgeUniqueid must be provided");
		return 0;
	}

	if (!ast_strlen_zero(id)) {
		ast_str_set(&id_text, 0, "ActionID: %s\r\n", id);
	}

	msg = stasis_cache_get(ast_bridge_cache(), ast_bridge_snapshot_type(), bridge_uniqueid);
	if (!msg) {
		astman_send_error(s, m, "Specified BridgeUniqueid not found");
		return 0;
	}

	snapshot = stasis_message_data(msg);
	bridge_info = ast_manager_build_bridge_state_string(snapshot);
	if (!bridge_info) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	astman_send_listack(s, m, "Bridge channel listing will follow", "start");

	list_data.id_text = ast_str_buffer(id_text);
	list_data.count = 0;
	ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, &list_data);

	astman_send_list_complete_start(s, m, "BridgeInfoComplete", list_data.count);
	if (!ast_strlen_zero(ast_str_buffer(bridge_info))) {
		astman_append(s, "%s", ast_str_buffer(bridge_info));
	}
	astman_send_list_complete_end(s);

	return 0;
}
Example #5
0
static int get_message_count(void *obj, void *arg, int flags)
{
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	struct mwi_stasis_subscription *mwi_stasis = obj;
	struct ast_sip_message_accumulator *counter = arg;
	struct ast_mwi_state *mwi_state;

	msg = stasis_cache_get(ast_mwi_state_cache(), ast_mwi_state_type(), mwi_stasis->mailbox);
	if (!msg) {
		return 0;
	}

	mwi_state = stasis_message_data(msg);
	counter->old_msgs += mwi_state->old_msgs;
	counter->new_msgs += mwi_state->new_msgs;
	return 0;
}
Example #6
0
struct ast_channel_snapshot *stasis_app_control_get_snapshot(
    const struct stasis_app_control *control)
{
    RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
    struct ast_channel_snapshot *snapshot;

    msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(),
                           stasis_app_control_get_channel_id(control));
    if (!msg) {
        return NULL;
    }

    snapshot = stasis_message_data(msg);
    ast_assert(snapshot != NULL);

    ao2_ref(snapshot, +1);
    return snapshot;
}
Example #7
0
struct ast_channel_snapshot *ast_channel_snapshot_get_latest_by_name(const char *name)
{
	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
	struct ast_channel_snapshot *snapshot;

	ast_assert(!ast_strlen_zero(name));

	message = stasis_cache_get(ast_channel_cache_by_name(),
			ast_channel_snapshot_type(),
			name);
	if (!message) {
		return NULL;
	}

	snapshot = stasis_message_data(message);
	if (!snapshot) {
		return NULL;
	}
	ao2_ref(snapshot, +1);
	return snapshot;
}