<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19731">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Use Caller ID for extension matching.<br><br>Currently, there is no Caller ID available to us when<br>checking for an extension match when handling INVITEs.<br>As a result, extension patterns that depend on the Caller ID<br>are not matched and calls may be incorrectly rejected.<br><br>The Caller ID is not available because the supplement that<br>adds Caller ID to the session does not execute until after<br>this check. Supplement callbacks cannot yet be executed<br>at this point since the session is not yet in the appropriate<br>state.<br><br>To fix this without impacting existing behavior, the Caller ID<br>number is now retrieved before attempting to pattern match.<br>This ensures pattern matching works correctly and there is<br>no behavior change to the way supplements are called.<br><br>ASTERISK-28767 #close<br><br>Change-Id: Iec7f5a3b90e51b65ccf74342f96bf80314b7cfc7<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip_caller_id.c<br>M res/res_pjsip_session.c<br>4 files changed, 298 insertions(+), 226 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 35c7339..3e19d8d 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -3604,6 +3604,25 @@</span><br><span> void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set the ID for a connected line update</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on failure, 0 on success</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_set_id_connected_line(struct pjsip_rx_data *rdata, struct ast_party_id *id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set the ID from an INVITE</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param id ID structure to fill</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param default_id Default ID structure with data to use (for non-trusted endpoints)</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param trusted_inbound Whether or not the endpoint is trusted (controls whether PAI or RPID can be used)</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on failure, 0 on success</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_set_id_from_invite(struct pjsip_rx_data *rdata, struct ast_party_id *id, struct ast_party_id *default_id, int trust_inbound);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Set name and number information on an identity header.</span><br><span> *</span><br><span> * \param pool Memory pool to use for string duplication</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 208a277..38a91bd 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -41,6 +41,7 @@</span><br><span> #include "asterisk/sorcery.h"</span><br><span> #include "asterisk/file.h"</span><br><span> #include "asterisk/cli.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/callerid.h"</span><br><span> #include "asterisk/res_pjsip_cli.h"</span><br><span> #include "asterisk/test.h"</span><br><span> #include "asterisk/res_pjsip_presence_xml.h"</span><br><span>@@ -2450,6 +2451,234 @@</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set an ast_party_id name and number based on an identity header.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param hdr From, P-Asserted-Identity, or Remote-Party-ID header on incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] id The ID to set data on</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void set_id_from_hdr(pjsip_fromto_hdr *hdr, struct ast_party_id *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char cid_name[AST_CHANNEL_NAME];</span><br><span style="color: hsl(120, 100%, 40%);">+ char cid_num[AST_CHANNEL_NAME];</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_name_addr *id_name_addr = (pjsip_name_addr *) hdr->uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *semi;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_pj_str(cid_num, ast_sip_pjsip_uri_get_username(hdr->uri), sizeof(cid_num));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Always truncate caller-id number at a semicolon. */</span><br><span style="color: hsl(120, 100%, 40%);">+ semi = strchr(cid_num, ';');</span><br><span style="color: hsl(120, 100%, 40%);">+ if (semi) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We need to be able to handle URI's looking like</span><br><span style="color: hsl(120, 100%, 40%);">+ * "sip:1235557890;phone-context=national@x.x.x.x;user=phone"</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Where the uri->user field will result in:</span><br><span style="color: hsl(120, 100%, 40%);">+ * "1235557890;phone-context=national"</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * People don't care about anything after the semicolon</span><br><span style="color: hsl(120, 100%, 40%);">+ * showing up on their displays even though the RFC</span><br><span style="color: hsl(120, 100%, 40%);">+ * allows the semicolon.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ *semi = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(id->name.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.str = ast_strdup(cid_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cid_name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.valid = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(id->number.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.str = ast_strdup(cid_num);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cid_num)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.valid = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get a P-Asserted-Identity or Remote-Party-ID header from an incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This function will parse the header as if it were a From header. This allows for us</span><br><span style="color: hsl(120, 100%, 40%);">+ * to easily manipulate the URI, as well as add, modify, or remove parameters from the</span><br><span style="color: hsl(120, 100%, 40%);">+ * header</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata The incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param header_name The name of the ID header to find</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL No ID header present or unable to parse ID header</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-NULL The parsed ID header</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *header_name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t from = { "From", 4 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_str_t header_content;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *parsed_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_generic_string_hdr *ident = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,</span><br><span style="color: hsl(120, 100%, 40%);">+ header_name, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ int parsed_len;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ident) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup_with_null(rdata->tp_info.pool, &header_content, &ident->hvalue);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ parsed_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from, header_content.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strlen(&header_content), &parsed_len);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!parsed_hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return parsed_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set an ast_party_id structure based on data in a P-Asserted-Identity header</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(120, 100%, 40%);">+ * the contents of a Privacy header in order to set presentation information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata The incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] id The ID to set</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Successfully set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int set_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t pai_str = { "P-Asserted-Identity", 19 };</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t privacy_str = { "Privacy", 7 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *pai_hdr = get_id_header(rdata, &pai_str);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_generic_string_hdr *privacy;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pai_hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ set_id_from_hdr(pai_hdr, id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!id->number.valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ privacy = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &privacy_str, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!privacy || !pj_stricmp2(&privacy->hvalue, "none")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set an ast_party_id structure based on data in a Remote-Party-ID header</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(120, 100%, 40%);">+ * the privacy and screen parameters in order to set presentation information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata The incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] id The ID to set</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Succesfully set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int set_id_from_rpid(pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t rpid_str = { "Remote-Party-ID", 15 };</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t privacy_str = { "privacy", 7 };</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t screen_str = { "screen", 6 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *rpid_hdr = get_id_header(rdata, &rpid_str);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *screen;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *privacy;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!rpid_hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ set_id_from_hdr(rpid_hdr, id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!id->number.valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ privacy = pjsip_param_find(&rpid_hdr->other_param, &privacy_str);</span><br><span style="color: hsl(120, 100%, 40%);">+ screen = pjsip_param_find(&rpid_hdr->other_param, &screen_str);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (privacy && !pj_stricmp2(&privacy->value, "full")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation = AST_PRES_RESTRICTED;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation = AST_PRES_RESTRICTED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation = AST_PRES_ALLOWED;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation = AST_PRES_ALLOWED;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (screen && !pj_stricmp2(&screen->value, "yes")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation |= AST_PRES_USER_NUMBER_PASSED_SCREEN;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation |= AST_PRES_USER_NUMBER_PASSED_SCREEN;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ id->number.presentation |= AST_PRES_USER_NUMBER_UNSCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ id->name.presentation |= AST_PRES_USER_NUMBER_UNSCREENED;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set an ast_party_id structure based on data in a From</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(120, 100%, 40%);">+ * no information from the message in order to set privacy. It relies on endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+ * configuration for privacy information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param rdata The incoming message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] id The ID to set</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Succesfully set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int set_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,</span><br><span style="color: hsl(120, 100%, 40%);">+ PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!from) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* This had better not happen */</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ set_id_from_hdr(from, id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!id->number.valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_set_id_connected_line(struct pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return !set_id_from_pai(rdata, id) || !set_id_from_rpid(rdata, id) ? 0 : -1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_set_id_from_invite(struct pjsip_rx_data *rdata, struct ast_party_id *id, struct ast_party_id *default_id, int trust_inbound)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (trust_inbound && (!set_id_from_pai(rdata, id) || !set_id_from_rpid(rdata, id))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Trusted: Check PAI and RPID */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(id->tag);</span><br><span style="color: hsl(120, 100%, 40%);">+ id->tag = ast_strdup(default_id->tag);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Not trusted: check the endpoint config or use From. */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_party_id_copy(id, default_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!default_id->number.valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ set_id_from_from(rdata, id);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Set name and number information on an identity header.</span><br><span> *</span><br><span> * \param pool Memory pool to use for string duplication</span><br><span>diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c</span><br><span>index 64fd8c7..b11e590 100644</span><br><span>--- a/res/res_pjsip_caller_id.c</span><br><span>+++ b/res/res_pjsip_caller_id.c</span><br><span>@@ -37,89 +37,6 @@</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Set an ast_party_id name and number based on an identity header.</span><br><span style="color: hsl(0, 100%, 40%);">- * \param hdr From, P-Asserted-Identity, or Remote-Party-ID header on incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- * \param[out] id The ID to set data on</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static void set_id_from_hdr(pjsip_fromto_hdr *hdr, struct ast_party_id *id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- char cid_name[AST_CHANNEL_NAME];</span><br><span style="color: hsl(0, 100%, 40%);">- char cid_num[AST_CHANNEL_NAME];</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_name_addr *id_name_addr = (pjsip_name_addr *) hdr->uri;</span><br><span style="color: hsl(0, 100%, 40%);">- char *semi;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_pj_str(cid_num, ast_sip_pjsip_uri_get_username(hdr->uri), sizeof(cid_num));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Always truncate caller-id number at a semicolon. */</span><br><span style="color: hsl(0, 100%, 40%);">- semi = strchr(cid_num, ';');</span><br><span style="color: hsl(0, 100%, 40%);">- if (semi) {</span><br><span style="color: hsl(0, 100%, 40%);">- /*</span><br><span style="color: hsl(0, 100%, 40%);">- * We need to be able to handle URI's looking like</span><br><span style="color: hsl(0, 100%, 40%);">- * "sip:1235557890;phone-context=national@x.x.x.x;user=phone"</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * Where the uri->user field will result in:</span><br><span style="color: hsl(0, 100%, 40%);">- * "1235557890;phone-context=national"</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * People don't care about anything after the semicolon</span><br><span style="color: hsl(0, 100%, 40%);">- * showing up on their displays even though the RFC</span><br><span style="color: hsl(0, 100%, 40%);">- * allows the semicolon.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">- *semi = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(id->name.str);</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.str = ast_strdup(cid_name);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(cid_name)) {</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.valid = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(id->number.str);</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.str = ast_strdup(cid_num);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(cid_num)) {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.valid = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Get a P-Asserted-Identity or Remote-Party-ID header from an incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This function will parse the header as if it were a From header. This allows for us</span><br><span style="color: hsl(0, 100%, 40%);">- * to easily manipulate the URI, as well as add, modify, or remove parameters from the</span><br><span style="color: hsl(0, 100%, 40%);">- * header</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * \param rdata The incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- * \param header_name The name of the ID header to find</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval NULL No ID header present or unable to parse ID header</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval non-NULL The parsed ID header</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *header_name)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t from = { "From", 4 };</span><br><span style="color: hsl(0, 100%, 40%);">- pj_str_t header_content;</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_fromto_hdr *parsed_hdr;</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_generic_string_hdr *ident = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,</span><br><span style="color: hsl(0, 100%, 40%);">- header_name, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- int parsed_len;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ident) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- pj_strdup_with_null(rdata->tp_info.pool, &header_content, &ident->hvalue);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- parsed_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from, header_content.ptr,</span><br><span style="color: hsl(0, 100%, 40%);">- pj_strlen(&header_content), &parsed_len);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!parsed_hdr) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return parsed_hdr;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \internal</span><br><span> * \brief Set an ANI2 integer based on OLI data in a From header</span><br><span> *</span><br><span> * This uses the contents of a From header in order to set Originating Line information.</span><br><span>@@ -161,130 +78,6 @@</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Set an ast_party_id structure based on data in a P-Asserted-Identity header</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(0, 100%, 40%);">- * the contents of a Privacy header in order to set presentation information.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * \param rdata The incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- * \param[out] id The ID to set</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval 0 Successfully set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int set_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t pai_str = { "P-Asserted-Identity", 19 };</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t privacy_str = { "Privacy", 7 };</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_fromto_hdr *pai_hdr = get_id_header(rdata, &pai_str);</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_generic_string_hdr *privacy;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!pai_hdr) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- set_id_from_hdr(pai_hdr, id);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!id->number.valid) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- privacy = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &privacy_str, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!privacy || !pj_stricmp2(&privacy->hvalue, "none")) {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Set an ast_party_id structure based on data in a Remote-Party-ID header</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(0, 100%, 40%);">- * the privacy and screen parameters in order to set presentation information.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * \param rdata The incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- * \param[out] id The ID to set</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval 0 Succesfully set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int set_id_from_rpid(pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t rpid_str = { "Remote-Party-ID", 15 };</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t privacy_str = { "privacy", 7 };</span><br><span style="color: hsl(0, 100%, 40%);">- static const pj_str_t screen_str = { "screen", 6 };</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_fromto_hdr *rpid_hdr = get_id_header(rdata, &rpid_str);</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_param *screen;</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_param *privacy;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!rpid_hdr) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- set_id_from_hdr(rpid_hdr, id);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!id->number.valid) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- privacy = pjsip_param_find(&rpid_hdr->other_param, &privacy_str);</span><br><span style="color: hsl(0, 100%, 40%);">- screen = pjsip_param_find(&rpid_hdr->other_param, &screen_str);</span><br><span style="color: hsl(0, 100%, 40%);">- if (privacy && !pj_stricmp2(&privacy->value, "full")) {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation = AST_PRES_RESTRICTED;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation = AST_PRES_RESTRICTED;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation = AST_PRES_ALLOWED;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation = AST_PRES_ALLOWED;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (screen && !pj_stricmp2(&screen->value, "yes")) {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation |= AST_PRES_USER_NUMBER_PASSED_SCREEN;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation |= AST_PRES_USER_NUMBER_PASSED_SCREEN;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- id->number.presentation |= AST_PRES_USER_NUMBER_UNSCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- id->name.presentation |= AST_PRES_USER_NUMBER_UNSCREENED;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Set an ast_party_id structure based on data in a From</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This makes use of \ref set_id_from_hdr for setting name and number. It uses</span><br><span style="color: hsl(0, 100%, 40%);">- * no information from the message in order to set privacy. It relies on endpoint</span><br><span style="color: hsl(0, 100%, 40%);">- * configuration for privacy information.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * \param rdata The incoming message</span><br><span style="color: hsl(0, 100%, 40%);">- * \param[out] id The ID to set</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval 0 Succesfully set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval non-zero Could not set the party ID</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int set_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,</span><br><span style="color: hsl(0, 100%, 40%);">- PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!from) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* This had better not happen */</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- set_id_from_hdr(from, id);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!id->number.valid) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \internal</span><br><span> * \brief Determine if a connected line update should be queued</span><br><span> *</span><br><span> * This uses information about the session and the ID that would be queued</span><br><span>@@ -388,7 +181,7 @@</span><br><span> }</span><br><span> </span><br><span> ast_party_id_init(&id);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!set_id_from_pai(rdata, &id) || !set_id_from_rpid(rdata, &id)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_sip_set_id_connected_line(rdata, &id)) {</span><br><span> if (should_queue_connected_line_update(session, &id)) {</span><br><span> queue_connected_line_update(session, &id);</span><br><span> }</span><br><span>@@ -417,22 +210,8 @@</span><br><span> * INVITE. Set the session ID directly because the channel</span><br><span> * has not been created yet.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- if (session->endpoint->id.trust_inbound</span><br><span style="color: hsl(0, 100%, 40%);">- && (!set_id_from_pai(rdata, &session->id)</span><br><span style="color: hsl(0, 100%, 40%);">- || !set_id_from_rpid(rdata, &session->id))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(session->id.tag);</span><br><span style="color: hsl(0, 100%, 40%);">- session->id.tag = ast_strdup(session->endpoint->id.self.tag);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_party_id_copy(&session->id, &session->endpoint->id.self);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!session->endpoint->id.self.number.valid) {</span><br><span style="color: hsl(0, 100%, 40%);">- set_id_from_from(rdata, &session->id);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (!set_id_from_oli(rdata, &ani2)) {</span><br><span style="color: hsl(0, 100%, 40%);">- session->ani2 = ani2;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- session->ani2 = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_set_id_from_invite(rdata, &session->id, &session->endpoint->id.self, session->endpoint->id.trust_inbound);</span><br><span style="color: hsl(120, 100%, 40%);">+ session->ani2 = set_id_from_oli(rdata, &ani2) ? 0 : ani2;</span><br><span> } else {</span><br><span> /*</span><br><span> * ReINVITE or UPDATE. Check for changes to the ID and queue</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 652b735..e7ba3ed 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -3641,6 +3641,21 @@</span><br><span> return session;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Fetch just the Caller ID number in order of PAI, RPID, From */</span><br><span style="color: hsl(120, 100%, 40%);">+static int fetch_callerid_num(struct ast_sip_session *session, pjsip_rx_data *rdata, char *buf, size_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_party_id id;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_party_id_init(&id);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_sip_set_id_from_invite(rdata, &id, &session->endpoint->id.self, session->endpoint->id.trust_inbound)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(buf, id.number.str, len);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_party_id_free(&id);</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> enum sip_get_destination_result {</span><br><span> /*! The extension was successfully found */</span><br><span> SIP_GET_DEST_EXTEN_FOUND,</span><br><span>@@ -3664,6 +3679,7 @@</span><br><span> */</span><br><span> static enum sip_get_destination_result get_destination(struct ast_sip_session *session, pjsip_rx_data *rdata)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ char cid_num[AST_CHANNEL_NAME];</span><br><span> pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;</span><br><span> struct ast_features_pickup_config *pickup_cfg;</span><br><span> const char *pickupexten;</span><br><span>@@ -3695,8 +3711,10 @@</span><br><span> ao2_ref(pickup_cfg, -1);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ fetch_callerid_num(session, rdata, cid_num, sizeof(cid_num));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!strcmp(session->exten, pickupexten) ||</span><br><span style="color: hsl(0, 100%, 40%);">- ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, S_OR(cid_num, NULL))) {</span><br><span> /*</span><br><span> * Save off the INVITE Request-URI in case it is</span><br><span> * needed: CHANNEL(pjsip,request_uri)</span><br><span>@@ -3711,7 +3729,7 @@</span><br><span> */</span><br><span> if (session->endpoint->allow_overlap && (</span><br><span> !strncmp(session->exten, pickupexten, strlen(session->exten)) ||</span><br><span style="color: hsl(0, 100%, 40%);">- ast_canmatch_extension(NULL, session->endpoint->context, session->exten, 1, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_canmatch_extension(NULL, session->endpoint->context, session->exten, 1, S_OR(cid_num, NULL)))) {</span><br><span> /* Overlap partial match */</span><br><span> return SIP_GET_DEST_EXTEN_PARTIAL;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19731">change 19731</a>. To unsubscribe, or for help writing mail filters, 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/c/asterisk/+/19731"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Iec7f5a3b90e51b65ccf74342f96bf80314b7cfc7 </div>
<div style="display:none"> Gerrit-Change-Number: 19731 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>