Module: sip-router Branch: master Commit: 9e1a1afd460183b3e00778ac7730ddfe6cf00a4d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9e1a1afd...
Author: Richard Good richard.good@smilecoms.com Committer: Richard Good richard.good@smilecoms.com Date: Wed Dec 3 16:25:39 2014 +0200
modules/ims_usrloc_pcscf: improved handling of wildcard userpart when matching contact When wildcard matching contact we now check that host part matches contact host part or alias param
---
modules/ims_usrloc_pcscf/udomain.c | 26 +++++++++++++++++++------- modules/ims_usrloc_pcscf/usrloc.c | 2 +- modules/ims_usrloc_pcscf/usrloc.h | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/modules/ims_usrloc_pcscf/udomain.c b/modules/ims_usrloc_pcscf/udomain.c index fcbdb6c..6087ee1 100644 --- a/modules/ims_usrloc_pcscf/udomain.c +++ b/modules/ims_usrloc_pcscf/udomain.c @@ -254,7 +254,7 @@ void mem_timer_udomain(udomain_t* _d)
while(ptr) { tmp = ptr; - ptr = ptr->next; + ptr = ptr->next; timer_pcontact(tmp); } @@ -451,7 +451,9 @@ int get_pcontact(udomain_t* _d, str* _contact, str* _received_host, int received ppublic_t* impu; struct sip_uri needle_uri, impu_uri; int port_match = 0; - + str alias_host = {0, 0}; + struct sip_uri contact_uri; + if (parse_uri(_contact->s, _contact->len, &needle_uri) != 0 ) { LM_ERR("failed to parse search URI [%.*s]\n", _contact->len, _contact->s); return 1; @@ -553,13 +555,23 @@ int get_pcontact(udomain_t* _d, str* _contact, str* _received_host, int received }
/* user parts must match (if not wildcarded) with either primary contact OR with any userpart in the implicit set (associated URIs).. */ - if (((needle_uri.user.len == 1) - && (memcmp(needle_uri.user.s, "*", 1) == 0)) - || ((needle_uri.user.len == c->contact_user.len) - && (memcmp(needle_uri.user.s, c->contact_user.s, - needle_uri.user.len) == 0))) { + if((needle_uri.user.len == c->contact_user.len) && (memcmp(needle_uri.user.s, c->contact_user.s,needle_uri.user.len) == 0)) { + LM_DBG("Needle user part matches contact user part therefore this is a match\n"); + *_c = c; + return 0; + } else if ((needle_uri.user.len == 1) && (memcmp(needle_uri.user.s, "*", 1) == 0)) { /*wild card*/ + LM_DBG("This a wild card user part - we must check if hosts match or needle host matches alias\n"); + if(memcmp(needle_uri.host.s, c->contact_host.s, needle_uri.host.len) == 0) { + LM_DBG("Needle host matches contact host therefore this is a match\n"); *_c = c; return 0; + } else if ((parse_uri(c->aor.s, c->aor.len, &contact_uri) == 0) && ((get_alias_host_from_contact(&contact_uri.params, &alias_host)) == 0) && + (memcmp(needle_uri.host.s, alias_host.s, alias_host.len) == 0)) { + LM_DBG("Needle host matches contact alias therefore this is a match\n"); + *_c = c; + return 0; + + } }
/* check impus user parts */ diff --git a/modules/ims_usrloc_pcscf/usrloc.c b/modules/ims_usrloc_pcscf/usrloc.c index 5172141..9de69b0 100644 --- a/modules/ims_usrloc_pcscf/usrloc.c +++ b/modules/ims_usrloc_pcscf/usrloc.c @@ -87,7 +87,7 @@ int bind_usrloc(usrloc_api_t* api) { #define ALIAS "alias=" #define ALIAS_LEN (sizeof(ALIAS) - 1)
-inline int get_alias_host_from_contact(str *contact_uri_params, str *alias_host) { +int get_alias_host_from_contact(str *contact_uri_params, str *alias_host) { char *rest, *sep; unsigned int rest_len;
diff --git a/modules/ims_usrloc_pcscf/usrloc.h b/modules/ims_usrloc_pcscf/usrloc.h index 92e287b..843827d 100644 --- a/modules/ims_usrloc_pcscf/usrloc.h +++ b/modules/ims_usrloc_pcscf/usrloc.h @@ -64,6 +64,8 @@ struct hslot; /*!< Hash table slot */ struct socket_info;
+int get_alias_host_from_contact(str *contact_uri_params, str *alias_host); + struct udomain { str* name; /*!< Domain name (NULL terminated) */ int size; /*!< Hash table size */