]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_pjsip: Assign SIPDOMAIN after creating a channel
authorIvan Poddubnyi <ivan.poddubny@gmail.com>
Tue, 29 Dec 2020 18:16:00 +0000 (19:16 +0100)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 13 Jan 2021 14:27:41 +0000 (08:27 -0600)
session->channel doesn't exist until chan_pjsip creates it, so intead of
setting a channel variable every new incoming call sets one and the same
global variable.

This patch moves the code to chan_pjsip so that SIPDOMAIN is set on
a newly created channel, it also removes a misleading reference to
channel->session used to fetch call pickup configuraion.

ASTERISK-29240

Change-Id: I90c9bbbed01f5d8863585631a29322ae4e046755

channels/chan_pjsip.c
res/res_pjsip_session.c

index 46fa32775c29a66f458514a661e653ffc8bfc5ce..f4409de4a78ed031c96582cd7f5a7877cb9d8f0d 100644 (file)
@@ -2980,6 +2980,18 @@ static void chan_pjsip_session_end(struct ast_sip_session *session)
        SCOPE_EXIT_RTN();
 }
 
+static void set_sipdomain_variable(struct ast_sip_session *session)
+{
+       pjsip_sip_uri *sip_ruri = pjsip_uri_get_uri(session->request_uri);
+       size_t size = pj_strlen(&sip_ruri->host) + 1;
+       char *domain = ast_alloca(size);
+
+       ast_copy_pj_str(domain, &sip_ruri->host, size);
+
+       pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
+       return;
+}
+
 /*! \brief Function called when a request is received on the session */
 static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
 {
@@ -3031,6 +3043,9 @@ static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct p
                SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Failed to allocate new PJSIP channel on incoming SIP INVITE\n",
                         ast_sip_session_get_name(session));
        }
+
+       set_sipdomain_variable(session);
+
        /* channel gets created on incoming request, but we wait to call start
            so other supplements have a chance to run */
        SCOPE_EXIT_RTN_VALUE(0, "%s\n", ast_sip_session_get_name(session));
index 82ef2aab56a5c198df14b5c515904c010ef93b0a..b09e5136df7337dd17b9f2164c3f9616ffcf8f49 100644 (file)
@@ -3733,7 +3733,7 @@ static enum sip_get_destination_result get_destination(struct ast_sip_session *s
         */
        AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(session->exten);
 
-       pickup_cfg = ast_get_chan_features_pickup_config(session->channel);
+       pickup_cfg = ast_get_chan_features_pickup_config(NULL); /* session->channel doesn't exist yet, using NULL */
        if (!pickup_cfg) {
                ast_log(LOG_ERROR, "%s: Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n",
                        ast_sip_session_get_name(session));
@@ -3745,12 +3745,6 @@ static enum sip_get_destination_result get_destination(struct ast_sip_session *s
 
        if (!strcmp(session->exten, pickupexten) ||
                ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) {
-               size_t size = pj_strlen(&sip_ruri->host) + 1;
-               char *domain = ast_alloca(size);
-
-               ast_copy_pj_str(domain, &sip_ruri->host, size);
-               pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
-
                /*
                 * Save off the INVITE Request-URI in case it is
                 * needed: CHANNEL(pjsip,request_uri)