struct ast_json *stasis_app_mailboxes_to_json()
{
	struct ast_json *array = ast_json_array_create();
	struct ao2_container *mailboxes;
	struct ao2_iterator iter;
	const struct ast_mwi_mailbox_object *mailbox;

	if (!array) {
		return NULL;
	}

	mailboxes = ast_mwi_mailbox_get_all();
	if (!mailboxes) {
		ast_json_unref(array);
		return NULL;
	}

	iter = ao2_iterator_init(mailboxes, 0);
	for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
		struct ast_json *appending = mailbox_to_json(mailbox);
		if (!appending || ast_json_array_append(array, appending)) {
			/* Failed to append individual mailbox to the array. Abort. */
			ast_json_unref(array);
			array = NULL;
			break;
		}
	}
	ao2_iterator_destroy(&iter);

	return array;
}
Example #2
0
int ast_mwi_mailbox_delete_all(void)
{
	struct ao2_container *mailboxes;

	mailboxes = ast_mwi_mailbox_get_all();
	if (mailboxes) {
		mwi_mailbox_delete_all(mailboxes);
		ao2_ref(mailboxes, -1);
	}
	return 0;
}
Example #3
0
/*!
 * \internal
 * \brief Post initial MWI count events.
 * \since 12.1.0
 *
 * \return Nothing
 */
static void mwi_initial_events(void)
{
	struct ao2_container *mailboxes;
	const struct ast_mwi_mailbox_object *mailbox;
	struct ao2_iterator iter;

	/* Get all mailbox counts. */
	mailboxes = ast_mwi_mailbox_get_all();
	if (!mailboxes) {
		return;
	}

	/* Post all mailbox counts. */
	iter = ao2_iterator_init(mailboxes, AO2_ITERATOR_UNLINK);
	for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
		mwi_post_event(mailbox);
	}
	ao2_iterator_destroy(&iter);

	ao2_ref(mailboxes, -1);
}
Example #4
0
static char *handle_mwi_list_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	struct ao2_container *mailboxes;

	switch (cmd) {
	case CLI_INIT:
		e->command = "mwi list all";
		e->usage =
			"Usage: mwi list all\n"
			"       List all external MWI mailboxes.\n";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	mailboxes = ast_mwi_mailbox_get_all();
	if (!mailboxes) {
		ast_cli(a->fd, "Failed to retrieve external MWI mailboxes.\n");
		return CLI_SUCCESS;
	}
	mwi_cli_list_mailboxes(a->fd, mailboxes);
	ao2_ref(mailboxes, -1);
	return CLI_SUCCESS;
}