예제 #1
0
static char *handle_mwi_list_like(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	struct ao2_container *mailboxes;
	const char *regex;

	switch (cmd) {
	case CLI_INIT:
		e->command = "mwi list like";
		e->usage =
			"Usage: mwi list like <pattern>\n"
			"       List external MWI mailboxes matching a regular expression.\n";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	if (a->argc != 4) {
		return CLI_SHOWUSAGE;
	}
	regex = a->argv[3];

	mailboxes = ast_mwi_mailbox_get_by_regex(regex);
	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;
}
예제 #2
0
static char *complete_mailbox(const char *word, int state)
{
	struct ao2_iterator iter;
	int wordlen = strlen(word);
	int which = 0;
	char *ret = NULL;
	char *regex;
	const struct ast_mwi_mailbox_object *mailbox;
	RAII_VAR(struct ao2_container *, mailboxes, NULL, ao2_cleanup);

	regex = ast_alloca(2 + wordlen);
	sprintf(regex, "^%s", word);/* Safe */

	mailboxes = ast_mwi_mailbox_get_by_regex(regex);
	if (!mailboxes) {
		return NULL;
	}

	iter = ao2_iterator_init(mailboxes, 0);
	for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
		if (++which > state) {
			ret = ast_strdup(ast_sorcery_object_get_id(mailbox));
			ast_mwi_mailbox_unref(mailbox);
			break;
		}
	}
	ao2_iterator_destroy(&iter);

	return ret;
}
예제 #3
0
int ast_mwi_mailbox_delete_by_regex(const char *regex)
{
	struct ao2_container *mailboxes;

	mailboxes = ast_mwi_mailbox_get_by_regex(regex);
	if (mailboxes) {
		mwi_mailbox_delete_all(mailboxes);
		ao2_ref(mailboxes, -1);
	}
	return 0;
}
예제 #4
0
/*!
 * \internal
 * \brief Get the requested mailboxes.
 * \since 12.1.0
 *
 * \param s AMI session.
 * \param m AMI message.
 *
 * \retval 0 to keep AMI connection.
 * \retval -1 to disconnect AMI connection.
 */
static int mwi_mailbox_get(struct mansession *s, const struct message *m)
{
	char id_text[256];
	const char *id;
	const char *mailbox_id = astman_get_header(m, "Mailbox");
	const struct ast_mwi_mailbox_object *mailbox;
	struct ao2_container *mailboxes;
	unsigned count;
	struct ao2_iterator iter;

	if (ast_strlen_zero(mailbox_id)) {
		astman_send_error(s, m, "Missing mailbox parameter in request");
		return 0;
	}

	if (*mailbox_id == '/') {
		struct ast_str *regex_string;

		regex_string = ast_str_create(strlen(mailbox_id) + 1);
		if (!regex_string) {
			astman_send_error(s, m, "Memory Allocation Failure");
			return 0;
		}

		/* Make "/regex/" into "regex" */
		if (ast_regex_string_to_regex_pattern(mailbox_id, &regex_string) != 0) {
			astman_send_error_va(s, m, "Mailbox regex format invalid in: %s", mailbox_id);
			ast_free(regex_string);
			return 0;
		}

		mailboxes = ast_mwi_mailbox_get_by_regex(ast_str_buffer(regex_string));
		ast_free(regex_string);
	} else {
		mailboxes = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
		if (mailboxes) {
			mailbox = ast_mwi_mailbox_get(mailbox_id);
			if (mailbox) {
				if (!ao2_link(mailboxes, (void *) mailbox)) {
					ao2_ref(mailboxes, -1);
					mailboxes = NULL;
				}
				ast_mwi_mailbox_unref(mailbox);
			}
		}
	}
	if (!mailboxes) {
		astman_send_error(s, m, "Mailbox container creation failure");
		return 0;
	}

	astman_send_listack(s, m, "Mailboxes will follow", "start");

	id = astman_get_header(m, "ActionID");
	if (!ast_strlen_zero(id)) {
		snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
	} else {
		id_text[0] = '\0';
	}

	/* Output mailbox list. */
	count = 0;
	iter = ao2_iterator_init(mailboxes, AO2_ITERATOR_UNLINK);
	for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
		++count;
		astman_append(s,
			"Event: MWIGet\r\n"
			"Mailbox: %s\r\n"
			"OldMessages: %u\r\n"
			"NewMessages: %u\r\n"
			"%s"
			"\r\n",
			ast_mwi_mailbox_get_id(mailbox),
			ast_mwi_mailbox_get_msgs_old(mailbox),
			ast_mwi_mailbox_get_msgs_new(mailbox),
			id_text);
	}
	ao2_iterator_destroy(&iter);
	ao2_ref(mailboxes, -1);

	astman_send_list_complete_start(s, m, "MWIGetComplete", count);
	astman_send_list_complete_end(s);

	return 0;
}