From 65e49d0ae4bfcc347a2b9722e9d024726086a114 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Mon, 21 May 2012 19:05:52 +0000 Subject: [PATCH] Add "send to voicemail" Digium phone functionality to Asterisk. This change accommodates two methods by which calls can be directed to a user's voicemail. * Incoming calls can be redirected to any user's voicemail. * Established calls can be blind transferred to any user's voicemail. Digium phones indicate the desire to direct a call to voicemail by using a Diversion header with a reason parameter of "send_to_vm". This patch adds the "send_to_vm" reason as a valid redirecting reason. In addition, chan_sip.c has been modified to update redirecting information on the transferred channel by reading a Diversion header on a REFER request. (closes issue AST-871) Reported by Malcolm Davenport Review: https://reviewboard.asterisk.org/r/1925 git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/1.8.11@367161 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 17 +++++++++++++++-- include/asterisk/callerid.h | 1 + main/callerid.c | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index dd4deccb6b..4821b85629 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -683,7 +683,8 @@ static const struct sip_reasons { { AST_REDIRECTING_REASON_FOLLOW_ME, "follow-me" }, { AST_REDIRECTING_REASON_OUT_OF_ORDER, "out-of-service" }, { AST_REDIRECTING_REASON_AWAY, "away" }, - { AST_REDIRECTING_REASON_CALL_FWD_DTE, "unknown"} + { AST_REDIRECTING_REASON_CALL_FWD_DTE, "unknown"}, + { AST_REDIRECTING_REASON_SEND_TO_VM, "send_to_vm"}, }; @@ -15390,7 +15391,7 @@ static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, c } /* Remove enclosing double-quotes */ if (*reason_param == '"') - ast_strip_quoted(reason_param, "\"", "\""); + reason_param = ast_strip_quoted(reason_param, "\"", "\""); if (!ast_strlen_zero(reason_param)) { sip_set_redirstr(p, reason_param); if (p->owner) { @@ -23673,6 +23674,8 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int int localtransfer = 0; int attendedtransfer = 0; int res = 0; + struct ast_party_redirecting redirecting; + struct ast_set_party_redirecting update_redirecting; if (req->debug) { ast_verbose("Call %s got a SIP call transfer from %s: (REFER)!\n", @@ -23977,6 +23980,16 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int } ast_set_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ + /* When a call is transferred to voicemail from a Digium phone, there may be + * a Diversion header present in the REFER with an appropriate reason parameter + * set. We need to update the redirecting information appropriately. + */ + ast_party_redirecting_init(&redirecting); + memset(&update_redirecting, 0, sizeof(update_redirecting)); + change_redirecting_information(p, req, &redirecting, &update_redirecting, FALSE); + ast_channel_update_redirecting(current.chan2, &redirecting, &update_redirecting); + ast_party_redirecting_free(&redirecting); + /* Do not hold the pvt lock during the indicate and async_goto. Those functions * lock channels which will invalidate locking order if the pvt lock is held.*/ /* For blind transfers, move the call to the new extensions. For attended transfers on multiple diff --git a/include/asterisk/callerid.h b/include/asterisk/callerid.h index e052f64781..eb25d27125 100644 --- a/include/asterisk/callerid.h +++ b/include/asterisk/callerid.h @@ -400,6 +400,7 @@ enum AST_REDIRECTING_REASON { AST_REDIRECTING_REASON_OUT_OF_ORDER, AST_REDIRECTING_REASON_AWAY, AST_REDIRECTING_REASON_CALL_FWD_DTE, /* This is something defined in Q.931, and no I don't know what it means */ + AST_REDIRECTING_REASON_SEND_TO_VM, }; /*! diff --git a/main/callerid.c b/main/callerid.c index 3af85b467b..d9c65c4161 100644 --- a/main/callerid.c +++ b/main/callerid.c @@ -1203,6 +1203,7 @@ static const struct ast_value_translation redirecting_reason_types[] = { { AST_REDIRECTING_REASON_OUT_OF_ORDER, "out_of_order", "Called DTE Out-Of-Order" }, { AST_REDIRECTING_REASON_AWAY, "away", "Callee is Away" }, { AST_REDIRECTING_REASON_CALL_FWD_DTE, "cf_dte", "Call Forwarding By The Called DTE" }, + { AST_REDIRECTING_REASON_SEND_TO_VM, "send_to_vm", "Call is being redirected to user's voicemail"}, /* *INDENT-ON* */ }; -- 2.47.2