<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7494">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Matthew Fredrickson: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Add new AMI action for app_voicemail<br><br>Currently, to figure out specified voicemail's status, there's only one<br>way to do it, which is use a VoicemailUserEntry AMI message.<br>But it consumed it too much resource(it check everything).<br>So, added new AMI action.<br><br>ASTERISK-27470<br><br>Change-Id: Ie4eba1424a142e5fbd1d9fb1821a3fc1a1e238b7<br>---<br>M apps/app_voicemail.c<br>1 file changed, 173 insertions(+), 79 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c<br>index d017301..c155186 100644<br>--- a/apps/app_voicemail.c<br>+++ b/apps/app_voicemail.c<br>@@ -463,6 +463,23 @@<br> <description><br> </description><br> </manager><br>+ <manager name="VoicemailUserStatus" language="en_US"><br>+ <synopsis><br>+ Show the status of given voicemail user's info.<br>+ </synopsis><br>+ <syntax><br>+ <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" /><br>+ <parameter name="Context" required="true"><br>+ <para>The context you want to check.</para><br>+ </parameter><br>+ <parameter name="Mailbox" required="true"><br>+ <para>The mailbox you want to check.</para><br>+ </parameter><br>+ </syntax><br>+ <description><br>+ <para>Retrieves the status of the given voicemail user.</para><br>+ </description><br>+ </manager><br> <manager name="VoicemailRefresh" language="en_US"><br> <synopsis><br> Tell Asterisk to poll mailboxes for a change<br>@@ -1105,6 +1122,8 @@<br> static const char *substitute_escapes(const char *value);<br> static int message_range_and_existence_check(struct vm_state *vms, const char *msg_ids [], size_t num_msgs, int *msg_nums, struct ast_vm_user *vmu);<br> static void notify_new_state(struct ast_vm_user *vmu);<br>+static int append_vmu_info_astman(struct mansession *s, struct ast_vm_user *vmu, const char* event_name, const char* actionid);<br>+<br> <br> /*!<br> * Place a message in the indicated folder<br>@@ -13222,6 +13241,105 @@<br> poll_thread = AST_PTHREADT_NULL;<br> }<br> <br>+/*! \brief Append vmu info string into given astman with event_name. */<br>+static int append_vmu_info_astman(<br>+ struct mansession *s,<br>+ struct ast_vm_user *vmu,<br>+ const char* event_name,<br>+ const char* actionid<br>+ )<br>+{<br>+ int new;<br>+ int old;<br>+<br>+ if((s == NULL) || (vmu == NULL) || (event_name == NULL) || (actionid == NULL)) {<br>+ ast_log(LOG_ERROR, "Wrong input parameter.");<br>+ return 0;<br>+ }<br>+<br>+ /* get mailbox count */<br>+ inboxcount(vmu->mailbox, &new, &old);<br>+<br>+ astman_append(s,<br>+ "Event: %s\r\n"<br>+ "%s"<br>+ "VMContext: %s\r\n"<br>+ "VoiceMailbox: %s\r\n"<br>+ "Fullname: %s\r\n"<br>+ "Email: %s\r\n"<br>+ "Pager: %s\r\n"<br>+ "ServerEmail: %s\r\n"<br>+ "FromString: %s\r\n"<br>+ "MailCommand: %s\r\n"<br>+ "Language: %s\r\n"<br>+ "TimeZone: %s\r\n"<br>+ "Callback: %s\r\n"<br>+ "Dialout: %s\r\n"<br>+ "UniqueID: %s\r\n"<br>+ "ExitContext: %s\r\n"<br>+ "SayDurationMinimum: %d\r\n"<br>+ "SayEnvelope: %s\r\n"<br>+ "SayCID: %s\r\n"<br>+ "AttachMessage: %s\r\n"<br>+ "AttachmentFormat: %s\r\n"<br>+ "DeleteMessage: %s\r\n"<br>+ "VolumeGain: %.2f\r\n"<br>+ "CanReview: %s\r\n"<br>+ "CallOperator: %s\r\n"<br>+ "MaxMessageCount: %d\r\n"<br>+ "MaxMessageLength: %d\r\n"<br>+ "NewMessageCount: %d\r\n"<br>+ "OldMessageCount: %d\r\n"<br>+#ifdef IMAP_STORAGE<br>+ "IMAPUser: %s\r\n"<br>+ "IMAPServer: %s\r\n"<br>+ "IMAPPort: %s\r\n"<br>+ "IMAPFlags: %s\r\n"<br>+#endif<br>+ "\r\n",<br>+<br>+ event_name,<br>+ actionid,<br>+ vmu->context,<br>+ vmu->mailbox,<br>+ vmu->fullname,<br>+ vmu->email,<br>+ vmu->pager,<br>+ ast_strlen_zero(vmu->serveremail) ? serveremail : vmu->serveremail,<br>+ ast_strlen_zero(vmu->fromstring) ? fromstring : vmu->fromstring,<br>+ mailcmd,<br>+ vmu->language,<br>+ vmu->zonetag,<br>+ vmu->callback,<br>+ vmu->dialout,<br>+ vmu->uniqueid,<br>+ vmu->exit,<br>+ vmu->saydurationm,<br>+ ast_test_flag(vmu, VM_ENVELOPE) ? "Yes" : "No",<br>+ ast_test_flag(vmu, VM_SAYCID) ? "Yes" : "No",<br>+ ast_test_flag(vmu, VM_ATTACH) ? "Yes" : "No",<br>+ vmu->attachfmt,<br>+ ast_test_flag(vmu, VM_DELETE) ? "Yes" : "No",<br>+ vmu->volgain,<br>+ ast_test_flag(vmu, VM_REVIEW) ? "Yes" : "No",<br>+ ast_test_flag(vmu, VM_OPERATOR) ? "Yes" : "No",<br>+ vmu->maxmsg,<br>+ vmu->maxsecs,<br>+ new,<br>+ old<br>+#ifdef IMAP_STORAGE<br>+ ,<br>+ vmu->imapuser,<br>+ vmu->imapserver,<br>+ vmu->imapport,<br>+ vmu->imapflags<br>+#endif<br>+ );<br>+<br>+ return 1;<br>+<br>+}<br>+<br> static int manager_voicemail_refresh(struct mansession *s, const struct message *m)<br> {<br> const char *context = astman_get_header(m, "Context");<br>@@ -13258,6 +13376,51 @@<br> return RESULT_SUCCESS;<br> }<br> <br>+static int manager_status_voicemail_user(struct mansession *s, const struct message *m)<br>+{<br>+ struct ast_vm_user *vmu = NULL;<br>+ const char *id = astman_get_header(m, "ActionID");<br>+ char actionid[128];<br>+ struct ast_vm_user svm;<br>+ int ret;<br>+<br>+ const char *context = astman_get_header(m, "Context");<br>+ const char *mailbox = astman_get_header(m, "Mailbox");<br>+<br>+ if ((ast_strlen_zero(context) || ast_strlen_zero(mailbox))) {<br>+ astman_send_error(s, m, "Need 'Context' and 'Mailbox' parameters.");<br>+ return RESULT_SUCCESS;<br>+ }<br>+<br>+ actionid[0] = '\0';<br>+ if (!ast_strlen_zero(id)) {<br>+ snprintf(actionid, sizeof(actionid), "ActionID: %s\r\n", id);<br>+ }<br>+<br>+ /* find user */<br>+ memset(&svm, 0, sizeof(svm));<br>+ vmu = find_user(&svm, context, mailbox);<br>+ if (!vmu) {<br>+ /* could not find it */<br>+ astman_send_ack(s, m, "There is no voicemail user of the given info.");<br>+ return RESULT_SUCCESS;<br>+ }<br>+<br>+ astman_send_listack(s, m, "Voicemail user detail will follow", "start");<br>+<br>+ /* append vmu info event */<br>+ ret = append_vmu_info_astman(s, vmu, "VoicemailUserDetail", actionid);<br>+ free_user(vmu);<br>+ if(ret == 0) {<br>+ ast_log(LOG_ERROR, "Could not append voicemail user info.");<br>+ }<br>+<br>+ astman_send_list_complete_start(s, m, "VoicemailUserDetailComplete", 1);<br>+ astman_send_list_complete_end(s);<br>+<br>+ return RESULT_SUCCESS;<br>+}<br>+<br> /*! \brief Manager list voicemail users command */<br> static int manager_list_voicemail_users(struct mansession *s, const struct message *m)<br> {<br>@@ -13265,6 +13428,7 @@<br> const char *id = astman_get_header(m, "ActionID");<br> char actionid[128];<br> int num_users = 0;<br>+ int ret;<br> <br> actionid[0] = '\0';<br> if (!ast_strlen_zero(id)) {<br>@@ -13282,86 +13446,14 @@<br> astman_send_listack(s, m, "Voicemail user list will follow", "start");<br> <br> AST_LIST_TRAVERSE(&users, vmu, list) {<br>- char dirname[256];<br>- int new, old;<br>- inboxcount(vmu->mailbox, &new, &old);<br>- <br>- make_dir(dirname, sizeof(dirname), vmu->context, vmu->mailbox, "INBOX");<br>- astman_append(s,<br>- "Event: VoicemailUserEntry\r\n"<br>- "%s"<br>- "VMContext: %s\r\n"<br>- "VoiceMailbox: %s\r\n"<br>- "Fullname: %s\r\n"<br>- "Email: %s\r\n"<br>- "Pager: %s\r\n"<br>- "ServerEmail: %s\r\n"<br>- "FromString: %s\r\n"<br>- "MailCommand: %s\r\n"<br>- "Language: %s\r\n"<br>- "TimeZone: %s\r\n"<br>- "Callback: %s\r\n"<br>- "Dialout: %s\r\n"<br>- "UniqueID: %s\r\n"<br>- "ExitContext: %s\r\n"<br>- "SayDurationMinimum: %d\r\n"<br>- "SayEnvelope: %s\r\n"<br>- "SayCID: %s\r\n"<br>- "AttachMessage: %s\r\n"<br>- "AttachmentFormat: %s\r\n"<br>- "DeleteMessage: %s\r\n"<br>- "VolumeGain: %.2f\r\n"<br>- "CanReview: %s\r\n"<br>- "CallOperator: %s\r\n"<br>- "MaxMessageCount: %d\r\n"<br>- "MaxMessageLength: %d\r\n"<br>- "NewMessageCount: %d\r\n"<br>- "OldMessageCount: %d\r\n"<br>-#ifdef IMAP_STORAGE<br>- "IMAPUser: %s\r\n"<br>- "IMAPServer: %s\r\n"<br>- "IMAPPort: %s\r\n"<br>- "IMAPFlags: %s\r\n"<br>-#endif<br>- "\r\n",<br>- actionid,<br>- vmu->context,<br>- vmu->mailbox,<br>- vmu->fullname,<br>- vmu->email,<br>- vmu->pager,<br>- ast_strlen_zero(vmu->serveremail) ? serveremail : vmu->serveremail,<br>- ast_strlen_zero(vmu->fromstring) ? fromstring : vmu->fromstring,<br>- mailcmd,<br>- vmu->language,<br>- vmu->zonetag,<br>- vmu->callback,<br>- vmu->dialout,<br>- vmu->uniqueid,<br>- vmu->exit,<br>- vmu->saydurationm,<br>- ast_test_flag(vmu, VM_ENVELOPE) ? "Yes" : "No",<br>- ast_test_flag(vmu, VM_SAYCID) ? "Yes" : "No",<br>- ast_test_flag(vmu, VM_ATTACH) ? "Yes" : "No",<br>- vmu->attachfmt,<br>- ast_test_flag(vmu, VM_DELETE) ? "Yes" : "No",<br>- vmu->volgain,<br>- ast_test_flag(vmu, VM_REVIEW) ? "Yes" : "No",<br>- ast_test_flag(vmu, VM_OPERATOR) ? "Yes" : "No",<br>- vmu->maxmsg,<br>- vmu->maxsecs,<br>- new,<br>- old<br>-#ifdef IMAP_STORAGE<br>- ,<br>- vmu->imapuser,<br>- vmu->imapserver,<br>- vmu->imapport,<br>- vmu->imapflags<br>-#endif<br>- );<br>+ /* append vmu info event */<br>+ ret = append_vmu_info_astman(s, vmu, "VoicemailUserEntry", actionid);<br>+ if(ret == 0) {<br>+ ast_log(LOG_ERROR, "Could not append voicemail user info.");<br>+ continue;<br>+ }<br> ++num_users;<br>- } <br>+ }<br> <br> astman_send_list_complete_start(s, m, "VoicemailUserEntryComplete", num_users);<br> astman_send_list_complete_end(s);<br>@@ -14891,6 +14983,7 @@<br> res |= ast_custom_function_unregister(&mailbox_exists_acf);<br> res |= ast_custom_function_unregister(&vm_info_acf);<br> res |= ast_manager_unregister("VoicemailUsersList");<br>+ res |= ast_manager_unregister("VoicemailUserStatus");<br> res |= ast_manager_unregister("VoicemailRefresh");<br> #ifdef TEST_FRAMEWORK<br> res |= AST_TEST_UNREGISTER(test_voicemail_vmsayname);<br>@@ -14968,6 +15061,7 @@<br> res |= ast_custom_function_register(&mailbox_exists_acf);<br> res |= ast_custom_function_register(&vm_info_acf);<br> res |= ast_manager_register_xml("VoicemailUsersList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, manager_list_voicemail_users);<br>+ res |= ast_manager_register_xml("VoicemailUserStatus", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, manager_status_voicemail_user);<br> res |= ast_manager_register_xml("VoicemailRefresh", EVENT_FLAG_USER, manager_voicemail_refresh);<br> #ifdef TEST_FRAMEWORK<br> res |= AST_TEST_REGISTER(test_voicemail_vmsayname);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7494">change 7494</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7494"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ie4eba1424a142e5fbd1d9fb1821a3fc1a1e238b7 </div>
<div style="display:none"> Gerrit-Change-Number: 7494 </div>
<div style="display:none"> Gerrit-PatchSet: 8 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: sungtae kim <pchero21@gmail.com> </div>