chan_pjsip: Add PJSIPHangup dialplan app and manager action

See UserNote below.

Exposed the existing Hangup AMI action in manager.c so we can use
all of it's channel search and AMI protocol handling without
duplicating that code in dialplan_functions.c.

Added a lookup function to res_pjsip.c that takes in the
string represenation of the pjsip_status_code enum and returns
the actual status code.  I.E.  ast_sip_str2rc("DECLINE") returns
603.  This allows the caller to specify PJSIPHangup(decline) in
the dialplan, just like Hangup(call_rejected).

Also extracted the XML documentation to its own file since it was
almost as large as the code itself.

UserNote: A new dialplan app PJSIPHangup and AMI action allows you
to hang up an unanswered incoming PJSIP call with a specific SIP
response code in the 400 -> 699 range.

(cherry picked from commit cd77953172)
This commit is contained in:
George Joseph
2023-10-31 15:08:14 -06:00
committed by Asterisk Development Team
parent f96d7ef7b5
commit 94f931a6d7
8 changed files with 992 additions and 562 deletions

View File

@@ -4649,7 +4649,9 @@ static int action_challenge(struct mansession *s, const struct message *m)
return 0;
}
static int action_hangup(struct mansession *s, const struct message *m)
int ast_manager_hangup_helper(struct mansession *s,
const struct message *m, manager_hangup_handler_t hangup_handler,
manager_hangup_cause_validator_t cause_validator)
{
struct ast_channel *c = NULL;
int causecode = 0; /* all values <= 0 mean 'do not set hangupcause in channel' */
@@ -4673,7 +4675,9 @@ static int action_hangup(struct mansession *s, const struct message *m)
idText[0] = '\0';
}
if (!ast_strlen_zero(cause)) {
if (cause_validator) {
causecode = cause_validator(name_or_regex, cause);
} else if (!ast_strlen_zero(cause)) {
char *endptr;
causecode = strtol(cause, &endptr, 10);
if (causecode < 0 || causecode > 127 || *endptr != '\0') {
@@ -4700,7 +4704,7 @@ static int action_hangup(struct mansession *s, const struct message *m)
ast_sockaddr_stringify_addr(&s->session->addr),
ast_channel_name(c));
ast_channel_softhangup_withcause_locked(c, causecode);
hangup_handler(c, causecode);
c = ast_channel_unref(c);
astman_send_ack(s, m, "Channel Hungup");
@@ -4746,7 +4750,7 @@ static int action_hangup(struct mansession *s, const struct message *m)
ast_sockaddr_stringify_addr(&s->session->addr),
ast_channel_name(c));
ast_channel_softhangup_withcause_locked(c, causecode);
hangup_handler(c, causecode);
channels_matched++;
astman_append(s,
@@ -4766,6 +4770,12 @@ static int action_hangup(struct mansession *s, const struct message *m)
return 0;
}
static int action_hangup(struct mansession *s, const struct message *m)
{
return ast_manager_hangup_helper(s, m,
ast_channel_softhangup_withcause_locked, NULL);
}
static int action_setvar(struct mansession *s, const struct message *m)
{
struct ast_channel *c = NULL;