Module: kamailio Branch: master Commit: 6ce335298da14211716209b8b8c12efedc86f53f URL: https://github.com/kamailio/kamailio/commit/6ce335298da14211716209b8b8c12efedc86f53f
Author: Victor Seva <[email protected]> Committer: Victor Seva <[email protected]> Date: 2025-10-30T18:42:38+01:00 ims_usrloc_scscf: improve find_contact_from_impu() * remove ':5060' from comparation * don't compare twice if there's no alias_term > ims_dialog [dlg_cb.c:271]: run_dlg_callbacks(): dialog=0x7fa0f03b9da0, type=16 > ims_usrloc_scscf [contact_dlg_handlers.c:65]: find_contact_from_impu(): > Looking for contact [sip:[email protected]:5060;transport=udp] for > IMPU [sip:[email protected]] > ims_usrloc_scscf [contact_dlg_handlers.c:102]: find_contact_from_impu(): > Comparing [10.17.10.37:5060;transport=udp] and [10.17.10.37;transport=udp] > ims_usrloc_scscf [contact_dlg_handlers.c:104]: find_contact_from_impu(): > Comparing [10.17.10.37:5060;transport=udp] and [10.17.10.37;transport=udp] > ims_usrloc_scscf [contact_dlg_handlers.c:113]: find_contact_from_impu(): > Skipping sip:[email protected];transport=udp > ims_usrloc_scscf [contact_dlg_handlers.c:118]: find_contact_from_impu(): > malformed contact, bailing search > ims_usrloc_scscf [contact_dlg_handlers.c:163]: contact_dlg_handler(): Unable > to find caller contact from dialog.... continuing > ims_usrloc_scscf [contact_dlg_handlers.c:65]: find_contact_from_impu(): > Looking for contact [sip:[email protected]:5060] > for IMPU [tel:+3910010008913] > ims_usrloc_scscf [contact_dlg_handlers.c:102]: find_contact_from_impu(): > Comparing [10.17.10.37:5060] and [10.17.10.37;transport=udp] > ims_usrloc_scscf [contact_dlg_handlers.c:104]: find_contact_from_impu(): > Comparing [10.17.10.37:5060] and [10.17.10.37;transport=udp] > ims_usrloc_scscf [contact_dlg_handlers.c:113]: find_contact_from_impu(): > Skipping sip:[email protected];transport=udp > ims_usrloc_scscf [contact_dlg_handlers.c:118]: find_contact_from_impu(): > malformed contact, bailing search > ims_usrloc_scscf [contact_dlg_handlers.c:189]: contact_dlg_handler(): Unable > to find callee contact from dialog.... continuing > ims_usrloc_scscf [contact_dlg_handlers.c:204]: contact_dlg_handler(): No > Contacts found for both caller && callee ... bailing --- Modified: src/modules/ims_usrloc_scscf/contact_dlg_handlers.c --- Diff: https://github.com/kamailio/kamailio/commit/6ce335298da14211716209b8b8c12efedc86f53f.diff Patch: https://github.com/kamailio/kamailio/commit/6ce335298da14211716209b8b8c12efedc86f53f.patch --- diff --git a/src/modules/ims_usrloc_scscf/contact_dlg_handlers.c b/src/modules/ims_usrloc_scscf/contact_dlg_handlers.c index c872fbef4dc..0e7dd87174a 100644 --- a/src/modules/ims_usrloc_scscf/contact_dlg_handlers.c +++ b/src/modules/ims_usrloc_scscf/contact_dlg_handlers.c @@ -44,6 +44,34 @@ void contact_dlg_create_handler( LM_DBG("Successfully registered contact dialog handler\n"); } + +/** removes the default port ':5060' from the string in order compare later + * returns: + * 0 => found + * 1 => not found + * < 0 => error + */ +static int filter_default_port(str *src, str *dst) +{ + str default_port = str_init(":5060"); + char *port; + + if((port = str_search(src, &default_port))) { + dst->len = port - src->s; + memcpy(dst->s, src->s, dst->len); + memcpy(dst->s + dst->len, port + 5, src->len - dst->len - 5); + dst->len = src->len - 5; + return 0; + } + if(dst->len < src->len) { + LM_BUG("dst len < src len\n"); + return -1; + } + dst->len = src->len; + memcpy(dst->s, src->s, src->len); + return 1; +} + /** * Search for a contact related to an IMPU based on an original contact string (uri) * @param impu impurecord we will search through @@ -58,24 +86,29 @@ static inline int find_contact_from_impu( char *s_term; char *c_term; char *alias_term; - + char sbuf[512], cbuf[512]; + str str_aor = {sbuf, 512}, str_c = {cbuf, 512}; if(!search_aor) return 1; - LM_DBG("Looking for contact [%.*s] for IMPU [%.*s]\n", search_aor->len, - search_aor->s, impu->public_identity.len, impu->public_identity.s); + if(filter_default_port(search_aor, &str_aor) < 0) { + return 1; + } + + LM_DBG("Looking for contact [%.*s] for IMPU [%.*s]\n", STR_FMT(&str_aor), + STR_FMT(&impu->public_identity)); /* Filter out sip: and anything before @ from search URI */ - s_term = strstr(search_aor->s, "@"); + s_term = strstr(str_aor.s, "@"); if(!s_term) { - s_term = strstr(search_aor->s, ":"); + s_term = strstr(str_aor.s, ":"); } s_term += 1; - if(s_term - search_aor->s >= search_aor->len) { + if(s_term - str_aor.s >= str_aor.len) { goto error; } - i_searchlen = search_aor->len - (s_term - search_aor->s); + i_searchlen = str_aor.len - (s_term - str_aor.s); /* Compare the entire contact including alias, if not until alias IP */ alias_term = strstr(s_term, "~"); @@ -90,28 +123,37 @@ static inline int find_contact_from_impu( while(impucontact) { if(impucontact->contact) { + // clean up previous contact + str_c.len = 512; + memset(str_c.s, 0, 512); - c_term = strstr(impucontact->contact->c.s, "@"); + if(filter_default_port(&impucontact->contact->c, &str_c) < 0) { + LM_DBG("Skipping %.*s\n", STR_FMT(&impucontact->contact->c)); + impucontact = impucontact->next; + continue; + } + c_term = strstr(str_c.s, "@"); if(!c_term) { - c_term = strstr(impucontact->contact->c.s, ":"); + c_term = strstr(str_c.s, ":"); } c_term += 1; - c_searchlen = impucontact->contact->c.len - - (c_term - impucontact->contact->c.s); - + c_searchlen = str_c.len - (c_term - str_c.s); LM_DBG("Comparing [%.*s] and [%.*s]\n", i_searchlen, s_term, c_searchlen, c_term); - LM_DBG("Comparing [%.*s] and [%.*s]\n", alias_searchlen, s_term, - c_searchlen, c_term); - if((strncmp(c_term, s_term, i_searchlen) == 0) - || (strncmp(c_term, s_term, alias_searchlen) == 0)) { + if(strncmp(c_term, s_term, i_searchlen) == 0) { *scontact = impucontact->contact; return 0; } + if(alias_term) { + LM_DBG("Comparing [%.*s] and [%.*s]\n", alias_searchlen, s_term, + c_searchlen, c_term); + if(strncmp(c_term, s_term, alias_searchlen) == 0) { + *scontact = impucontact->contact; + return 0; + } + } + LM_DBG("Skipping %.*s\n", STR_FMT(&impucontact->contact->c)); } - if(impucontact->contact) - LM_DBG("Skipping %.*s\n", impucontact->contact->c.len, - impucontact->contact->c.s); impucontact = impucontact->next; } error: _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
