From cad9b171c274563d7265b40198e09ee8526fe758 Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Thu, 17 Jun 2021 18:09:03 +0300 Subject: [PATCH] registrar: Update the Contact URI on param-based matching (cherry picked from commit 8cc4b3249625802f2b3a11fb5f8b264cae6c6a11) --- modules/registrar/save.c | 4 ++-- modules/usrloc/urecord.c | 3 +++ parser/parse_uri.h | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/registrar/save.c b/modules/registrar/save.c index 7724da7be6c..9940067bde9 100644 --- a/modules/registrar/save.c +++ b/modules/registrar/save.c @@ -444,7 +444,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, /* pack the contact_info */ if ( (ci=pack_ci( 0, _c, e, 0, ul.nat_flag, _sctx->flags, - &_sctx->ownership_tag, NULL))==0 ) { + &_sctx->ownership_tag, &_sctx->cmatch))==0 ) { LM_ERR("failed to extract contact info\n"); goto error; } @@ -511,7 +511,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, /* pack the contact specific info */ if ( (ci=pack_ci( 0, _c, e, 0, ul.nat_flag, _sctx->flags, - &_sctx->ownership_tag, NULL))==0 ) { + &_sctx->ownership_tag, &_sctx->cmatch))==0 ) { LM_ERR("failed to pack contact specific info\n"); goto error; } diff --git a/modules/usrloc/urecord.c b/modules/usrloc/urecord.c index 2d672390be9..e78b52b086a 100644 --- a/modules/usrloc/urecord.c +++ b/modules/usrloc/urecord.c @@ -990,6 +990,9 @@ static inline struct ucontact* contact_params_match(ucontact_t* contacts, } for (param = _params; param; param = param->next) { + /* a bit counter-intuitive, but, according to RFC 3261 ยง 19.1.4, if + * an unknown URI parameter is missing from either URI, + * the matching of that parameter is successful! */ if (get_uri_param_val(&ct, ¶m->s, &v1) != 0 || get_uri_param_val(&cti, ¶m->s, &v2) != 0) continue; diff --git a/parser/parse_uri.h b/parser/parse_uri.h index d55355f8a61..4f55391d067 100644 --- a/parser/parse_uri.h +++ b/parser/parse_uri.h @@ -114,7 +114,10 @@ static inline unsigned short get_uri_port(struct sip_uri* _uri, * @param - URI param name to search for * @val - output value * - * Return: 0 on parser-recognized parameters or success, -1 otherwise + * Return: + * 0 on RFC-recognized parameters (even if they are missing!) + * or successful search of unknown ones + * -1 otherwise */ static inline int get_uri_param_val(const struct sip_uri *uri, const str *param, str *val)