/*! * \internal * \brief Update the specified mailbox. * \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_update(struct mansession *s, const struct message *m) { const char *mailbox_id = astman_get_header(m, "Mailbox"); const char *msgs_old = astman_get_header(m, "OldMessages"); const char *msgs_new = astman_get_header(m, "NewMessages"); struct ast_mwi_mailbox_object *mailbox; unsigned int num_old; unsigned int num_new; if (ast_strlen_zero(mailbox_id)) { astman_send_error(s, m, "Missing mailbox parameter in request"); return 0; } num_old = 0; if (!ast_strlen_zero(msgs_old)) { if (sscanf(msgs_old, "%u", &num_old) != 1) { astman_send_error_va(s, m, "Invalid OldMessages: %s", msgs_old); return 0; } } num_new = 0; if (!ast_strlen_zero(msgs_new)) { if (sscanf(msgs_new, "%u", &num_new) != 1) { astman_send_error_va(s, m, "Invalid NewMessages: %s", msgs_new); return 0; } } mailbox = ast_mwi_mailbox_alloc(mailbox_id); if (!mailbox) { astman_send_error(s, m, "Mailbox object creation failure"); return 0; } /* Update external mailbox. */ ast_mwi_mailbox_set_msgs_old(mailbox, num_old); ast_mwi_mailbox_set_msgs_new(mailbox, num_new); if (ast_mwi_mailbox_update(mailbox)) { astman_send_error(s, m, "Update attempt failed"); } else { astman_send_ack(s, m, NULL); } ast_mwi_mailbox_unref(mailbox); return 0; }
int stasis_app_mailbox_update( const char *name, int old_messages, int new_messages) { struct ast_mwi_mailbox_object *mailbox; int res = 0; mailbox = ast_mwi_mailbox_alloc(name); if (!mailbox) { return -1; } ast_mwi_mailbox_set_msgs_new(mailbox, new_messages); ast_mwi_mailbox_set_msgs_old(mailbox, old_messages); if (ast_mwi_mailbox_update(mailbox)) { res = -1; } ast_mwi_mailbox_unref(mailbox); return res; }
static char *handle_mwi_update_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_mwi_mailbox_object *mailbox; const char *mailbox_id; unsigned int num_new; unsigned int num_old; switch (cmd) { case CLI_INIT: e->command = "mwi update mailbox"; e->usage = "Usage: mwi update mailbox <mailbox_id> [<new> [<old>]]\n" " Update a specific external MWI mailbox.\n"; return NULL; case CLI_GENERATE: if (a->pos == 3) { return complete_mailbox(a->word, a->n); } return NULL; } if (a->argc < 4 || 6 < a->argc) { return CLI_SHOWUSAGE; } mailbox_id = a->argv[3]; num_new = 0; if (4 < a->argc) { const char *count_new = a->argv[4]; if (sscanf(count_new, "%u", &num_new) != 1) { ast_cli(a->fd, "Invalid NewMessages: '%s'.\n", count_new); return CLI_SHOWUSAGE; } } num_old = 0; if (5 < a->argc) { const char *count_old = a->argv[5]; if (sscanf(count_old, "%u", &num_old) != 1) { ast_cli(a->fd, "Invalid OldMessages: '%s'.\n", count_old); return CLI_SHOWUSAGE; } } mailbox = ast_mwi_mailbox_alloc(mailbox_id); if (mailbox) { ast_mwi_mailbox_set_msgs_new(mailbox, num_new); ast_mwi_mailbox_set_msgs_old(mailbox, num_old); if (ast_mwi_mailbox_update(mailbox)) { ast_cli(a->fd, "Could not update mailbox %s.\n", ast_sorcery_object_get_id(mailbox)); } else { ast_cli(a->fd, "Updated mailbox %s.\n", ast_sorcery_object_get_id(mailbox)); } ast_mwi_mailbox_unref(mailbox); } return CLI_SUCCESS; }