From 78546868f9a01c498e0c3cf4db42dbe819a346bc Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Fri, 10 Nov 2023 08:30:33 -0500 Subject: [PATCH] sig_analog: Add Last Number Redial feature. This adds the Last Number Redial feature to simple switch. UserNote: Users can now redial the last number called if the lastnumredial setting is set to yes. Resolves: #437 --- channels/chan_dahdi.c | 4 ++++ channels/chan_dahdi.h | 2 ++ channels/sig_analog.c | 21 +++++++++++++++++++++ channels/sig_analog.h | 2 ++ configs/samples/chan_dahdi.conf.sample | 5 +++++ 5 files changed, 34 insertions(+) diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index f2960ef0a1..e2a0117e3a 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -13109,6 +13109,7 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf, tmp->permhidecallerid = conf->chan.hidecallerid; tmp->hidecalleridname = conf->chan.hidecalleridname; tmp->callreturn = conf->chan.callreturn; + tmp->lastnumredial = conf->chan.lastnumredial; /* Not used in DAHDI pvt, only analog pvt */ tmp->echocancel = conf->chan.echocancel; tmp->echotraining = conf->chan.echotraining; tmp->pulse = conf->chan.pulse; @@ -13404,6 +13405,7 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf, analog_p->permcallwaiting = conf->chan.callwaiting; /* permcallwaiting possibly modified in analog_config_complete */ analog_p->calledsubscriberheld = conf->chan.calledsubscriberheld; /* Only actually used in analog pvt, not DAHDI pvt */ analog_p->callreturn = conf->chan.callreturn; + analog_p->lastnumredial = conf->chan.lastnumredial; /* Only actually used in analog pvt, not DAHDI pvt */ analog_p->cancallforward = conf->chan.cancallforward; analog_p->canpark = conf->chan.canpark; analog_p->dahditrcallerid = conf->chan.dahditrcallerid; @@ -18653,6 +18655,8 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct parse_busy_pattern(v, &confp->chan.busy_cadence); } else if (!strcasecmp(v->name, "calledsubscriberheld")) { confp->chan.calledsubscriberheld = ast_true(v->value); + } else if (!strcasecmp(v->name, "lastnumredial")) { + confp->chan.lastnumredial = ast_true(v->value); } else if (!strcasecmp(v->name, "callprogress")) { confp->chan.callprogress &= ~CALLPROGRESS_PROGRESS; if (ast_true(v->value)) diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h index 4431efd913..72bd234f84 100644 --- a/channels/chan_dahdi.h +++ b/channels/chan_dahdi.h @@ -440,6 +440,8 @@ struct dahdi_pvt { * \note Used by SS7. Otherwise set but not used. */ unsigned int inservice:1; + /*! *\brief TRUE if last number redial enabled */ + unsigned int lastnumredial:1; /*! * \brief Bitmask for the channel being locally blocked. * \note Applies to SS7 and MFCR2 channels. diff --git a/channels/sig_analog.c b/channels/sig_analog.c index e23cf072c4..e477d5d0cf 100644 --- a/channels/sig_analog.c +++ b/channels/sig_analog.c @@ -1721,6 +1721,9 @@ static int analog_canmatch_featurecode(const char *pickupexten, const char *exte if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) { return 1; } + if (exten[0] == '#' && extlen < 2) { + return 1; /* Could match ## */ + } /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */ if (exten[0] == '*' && extlen < 3) { if (extlen == 1) { @@ -2208,6 +2211,19 @@ static void *__analog_ss_thread(void *data) if (ast_parking_provider_registered()) { is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten); } + if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) { + /* Last Number Redial */ + if (!ast_strlen_zero(p->lastexten)) { + ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel); + ast_copy_string(exten, p->lastexten, sizeof(exten)); + } else { + ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel); + res = analog_play_tone(p, idx, ANALOG_TONE_CONGESTION); + analog_wait_event(p); + ast_hangup(chan); + goto quit; + } + } if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) { if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) { if (getforward) { @@ -2230,6 +2246,11 @@ static void *__analog_ss_thread(void *data) ast_channel_lock(chan); ast_channel_exten_set(chan, exten); + /* Save the last number dialed, for Last Number Redial. */ + if (!p->immediate) { + ast_copy_string(p->lastexten, exten, sizeof(p->lastexten)); + } + /* Properly set the presentation. * We need to do this here as well, because p->hidecallerid might be set * due to permanent blocking, not star-67/star-82 usage. */ diff --git a/channels/sig_analog.h b/channels/sig_analog.h index 81043f39a5..023170cf7f 100644 --- a/channels/sig_analog.h +++ b/channels/sig_analog.h @@ -297,6 +297,7 @@ struct analog_pvt { unsigned int hanguponpolarityswitch:1; unsigned int immediate:1; unsigned int immediatering:1; /*!< TRUE if ringing should be provided for immediate execution */ + unsigned int lastnumredial:1; /*!< TRUE if last number redial allowed */ unsigned int permcallwaiting:1; /*!< TRUE if call waiting is enabled. (Configured option) */ unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */ unsigned int pulse:1; @@ -352,6 +353,7 @@ struct analog_pvt { char callwait_name[AST_MAX_EXTENSION]; char lastcid_num[AST_MAX_EXTENSION]; char lastcid_name[AST_MAX_EXTENSION]; + char lastexten[AST_MAX_EXTENSION]; /*!< Last number dialed */ struct ast_party_caller caller; int redirecting_reason; /*!< Redirecting reason */ diff --git a/configs/samples/chan_dahdi.conf.sample b/configs/samples/chan_dahdi.conf.sample index f36fe56ce3..21c7954e1f 100644 --- a/configs/samples/chan_dahdi.conf.sample +++ b/configs/samples/chan_dahdi.conf.sample @@ -814,6 +814,11 @@ cancallforward=yes ; callreturn=yes ; +; Whether or not to allow redialing the last number called using Last Number Redial +; (##, if your dialplan doesn't catch this first) +; +;lastnumredial=yes +; ; Stutter dialtone support: If voicemail is received in the mailbox then ; taking the phone off hook will cause a stutter dialtone instead of a ; normal one.