]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_callerid: Fix OLI parsing
authorNaveen Albert <asterisk@phreaknet.org>
Sun, 24 Oct 2021 18:38:13 +0000 (18:38 +0000)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Tue, 16 Nov 2021 18:47:01 +0000 (12:47 -0600)
Fix parsing of ANI2/OLI information, since it was previously
parsing the user, when it should have been parsing other_param.

Also improves the parsing by using pjproject native functions
rather than trying to parse the parameters ourselves like
chan_sip did. A previous attempt at this caused a crash, but
this works correctly now.

ASTERISK-29703 #close

Change-Id: I8f3c79032d9ea1a21d16f8e11f22bd8d887738a1

res/res_pjsip_caller_id.c

index 3b871cdd6aa39341bb731ca66746a9132cc92a10..f1c89ee7d0d9e48d673d047665abb1bd892b0457 100644 (file)
@@ -133,43 +133,32 @@ static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *hea
  */
 static int set_id_from_oli(pjsip_rx_data *rdata, int *ani2)
 {
-       char fromhdr[AST_CHANNEL_NAME];
-       const char *s = NULL;
-       pjsip_sip_uri *uri;
-       pjsip_name_addr *id_name_addr;
+       char oli[AST_CHANNEL_NAME];
+
+       pjsip_param *oli1, *oli2, *oli3;
+
+       static const pj_str_t oli_str1 = { "isup-oli", 8 };
+       static const pj_str_t oli_str2 = { "ss7-oli", 7 };
+       static const pj_str_t oli_str3 = { "oli", 3 };
 
        pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,
                        PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);
-       id_name_addr = (pjsip_name_addr *) from->uri;
 
        if (!from) {
-               /* This had better not happen */
-               return -1;
+               return -1; /* This had better not happen */
        }
 
-       uri = pjsip_uri_get_uri(id_name_addr);
-       ast_copy_pj_str(fromhdr, &uri->user, sizeof(fromhdr));
-
-       /* Look for the possible OLI tags. */
-       if ((s = strcasestr(fromhdr, ";isup-oli="))) {
-               s += 10;
-       } else if ((s = strcasestr(fromhdr, ";ss7-oli="))) {
-               s += 9;
-       } else if ((s = strcasestr(fromhdr, ";oli="))) {
-               s += 5;
-       }
-
-       if (ast_strlen_zero(s)) {
-               /* OLI tag is missing, or present with nothing following the '=' sign */
+       if ((oli1 = pjsip_param_find(&from->other_param, &oli_str1))) {
+               ast_copy_pj_str(oli, &oli1->value, sizeof(oli));
+       } else if ((oli2 = pjsip_param_find(&from->other_param, &oli_str2))) {
+               ast_copy_pj_str(oli, &oli2->value, sizeof(oli));
+       } else if ((oli3 = pjsip_param_find(&from->other_param, &oli_str3))) {
+               ast_copy_pj_str(oli, &oli3->value, sizeof(oli));
+       } else {
                return -1;
        }
 
-       /* just in case OLI is quoted */
-       if (*s == '\"') {
-               s++;
-       }
-
-       return ast_str_to_int(s, ani2);
+       return ast_str_to_int(oli, ani2);
 }
 
 /*!