Module: kamailio
Branch: 5.7
Commit: f9e8112e87f914549368d04e8fd9b68765d24771
URL: 
https://github.com/kamailio/kamailio/commit/f9e8112e87f914549368d04e8fd9b68765d24771

Author: anmartan <a.mar...@zaleos.net>
Committer: Xenofon Karamanos <22965395+xkara...@users.noreply.github.com>
Date: 2024-11-06T13:26:43Z

core: Improved URN parsing according to RFC8141

- 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.

(cherry picked from commit 6cdd56bb85e1a10ebbb29c2633fb47bf7b56585e)

---

Modified: src/core/parser/parse_uri.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/f9e8112e87f914549368d04e8fd9b68765d24771.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f9e8112e87f914549368d04e8fd9b68765d24771.patch

---

diff --git a/src/core/parser/parse_uri.c b/src/core/parser/parse_uri.c
index 9ccb62ee51e..4150c1598d6 100644
--- a/src/core/parser/parse_uri.c
+++ b/src/core/parser/parse_uri.c
@@ -237,28 +237,30 @@ 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) {    \
+                       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 '@':                      \
                goto error_bad_char
 
 
@@ -493,7 +495,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:

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to