Module: kamailio
Branch: master
Commit: d1584cff4766d45147cc3ed88da91ab691437799
URL:
https://github.com/kamailio/kamailio/commit/d1584cff4766d45147cc3ed88da91ab…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-04-04T09:59:06+02:00
core: functions for light comparison of uri values
- match uri type, user, host, port and proto, but skip params matching
---
Modified: src/core/strutils.c
Modified: src/core/strutils.h
---
Diff:
https://github.com/kamailio/kamailio/commit/d1584cff4766d45147cc3ed88da91ab…
Patch:
https://github.com/kamailio/kamailio/commit/d1584cff4766d45147cc3ed88da91ab…
---
diff --git a/src/core/strutils.c b/src/core/strutils.c
index 7df31727cb..e106dfe713 100644
--- a/src/core/strutils.c
+++ b/src/core/strutils.c
@@ -496,13 +496,13 @@ int cmp_str_params(str *s1, str *s2)
}
/**
- * Compare SIP URI as per RFC3261, 19.1.4
+ * Compare SIP URI in light mode or as per RFC3261, 19.1.4
* return:
* - 0: match
* - >0: no match
* - <0: error
*/
-int cmp_uri(struct sip_uri *uri1, struct sip_uri *uri2)
+int cmp_uri_mode(struct sip_uri *uri1, struct sip_uri *uri2, int cmode)
{
if(uri1->type!=uri2->type)
return 1;
@@ -520,6 +520,13 @@ int cmp_uri(struct sip_uri *uri1, struct sip_uri *uri2)
return 1;
if(cmpi_str(&uri1->host, &uri2->host)!=0)
return 1;
+ if(cmode == 1) {
+ /* compare mode light - proto should be the same for match */
+ if(uri1->proto == uri2->proto) {
+ return 0;
+ }
+ return 1;
+ }
/* if no params, we are done */
if(uri1->params.len==0 && uri2->params.len==0)
return 0;
@@ -548,6 +555,30 @@ int cmp_uri(struct sip_uri *uri1, struct sip_uri *uri2)
return cmp_str_params(&uri1->params, &uri2->params);
}
+/**
+ * Compare SIP URI as per RFC3261, 19.1.4 (match also params)
+ * return:
+ * - 0: match
+ * - >0: no match
+ * - <0: error
+ */
+int cmp_uri(struct sip_uri *uri1, struct sip_uri *uri2)
+{
+ return cmp_uri_mode(uri1, uri2, 0);
+}
+
+/**
+ * Compare SIP URI light - uri type, user, host, port and proto match
+ * return:
+ * - 0: match
+ * - >0: no match
+ * - <0: error
+ */
+int cmp_uri_light(struct sip_uri *uri1, struct sip_uri *uri2)
+{
+ return cmp_uri_mode(uri1, uri2, 1);
+}
+
/**
* return:
* - 0: match
@@ -567,6 +598,25 @@ int cmp_uri_str(str *s1, str *s2)
return cmp_uri(&uri1, &uri2);
}
+/**
+ * return:
+ * - 0: match
+ * - >0: no match
+ * - <0: error
+ */
+int cmp_uri_light_str(str *s1, str *s2)
+{
+ struct sip_uri uri1;
+ struct sip_uri uri2;
+
+ /* todo: parse uri and compare the parts */
+ if(parse_uri(s1->s, s1->len, &uri1)!=0)
+ return -1;
+ if(parse_uri(s2->s, s2->len, &uri2)!=0)
+ return -1;
+ return cmp_uri_light(&uri1, &uri2);
+}
+
/**
* Compare SIP AoR
* - match user, host and port (if port missing, assume 5060)
diff --git a/src/core/strutils.h b/src/core/strutils.h
index 8b20f72e44..4747f898fd 100644
--- a/src/core/strutils.h
+++ b/src/core/strutils.h
@@ -45,6 +45,7 @@ int cmpi_str(str *s1, str *s2);
int cmp_hdrname_str(str *s1, str *s2);
int cmp_hdrname_strzn(str *s1, char *s2, size_t n);
int cmp_uri_str(str *s1, str *s2);
+int cmp_uri_light_str(str *s1, str *s2);
int cmp_aor_str(str *s1, str *s2);
/* str regexp replace */