Skip to content

Commit

Permalink
core: functions for light comparison of uri values
Browse files Browse the repository at this point in the history
- match uri type, user, host, port and proto, but skip params matching
  • Loading branch information
miconda committed Apr 4, 2020
1 parent 5e484f1 commit d1584cf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/core/strutils.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/core/strutils.h
Expand Up @@ -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 */
Expand Down

0 comments on commit d1584cf

Please sign in to comment.