Skip to content

Commit

Permalink
core: Improved URN parsing according to RFC8141
Browse files Browse the repository at this point in the history
- Improved URN parsing to allow consuming URNs that contain 3 or more colons. Previosly URI parser treated some of the colons as separator between host and port causing the URN parsing to fail.
  • Loading branch information
anmartan committed Jul 5, 2024
1 parent dc7fc82 commit f02261b
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/core/parser/parse_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
char *end;
char *pass;
int found_user;
int found_host;
int error_headers;
uint32_t scheme;
uri_type backup_urit;
Expand Down Expand Up @@ -237,28 +238,33 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
} else \
goto error_bad_char

#define check_host_end \
case ':': \
/* found the host */ \
uri->host.s = s; \
uri->host.len = p - s; \
state = URI_PORT; \
s = p + 1; \
break; \
case ';': \
uri->host.s = s; \
uri->host.len = p - s; \
state = URI_PARAM; \
s = p + 1; \
break; \
case '?': \
uri->host.s = s; \
uri->host.len = p - s; \
state = URI_HEADERS; \
s = p + 1; \
break; \
case '&': \
case '@': \
#define check_host_end \
case ':': \
/* found the host */ \
if(scheme != URN_SCH || found_host == 0) { \
uri->host.s = s; \
found_host = 1; \
} \
uri->host.len = p - uri->host.s; \
if(scheme != URN_SCH) { \
state = URI_PORT; \
s = p + 1; \
} \
break; \
case ';': \
uri->host.s = s; \
uri->host.len = p - s; \
state = URI_PARAM; \
s = p + 1; \
break; \
case '?': \
uri->host.s = s; \
uri->host.len = p - s; \
state = URI_HEADERS; \
s = p + 1; \
break; \
case '&': \
case '@': \
goto error_bad_char


Expand Down Expand Up @@ -445,6 +451,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
end = buf + len;
p = buf + 4;
found_user = 0;
found_host = 0;
error_headers = 0;
b = v = 0;
param = param_val = 0;
Expand Down Expand Up @@ -493,7 +500,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
case '@': /* error no user part, or
* be forgiving and accept it ? */
default:
state = URI_USER;
state = (scheme == URN_SCH) ? URI_HOST : URI_USER;
}
break;
case URI_USER:
Expand Down

0 comments on commit f02261b

Please sign in to comment.