You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-commits@axis.apache.org by ro...@apache.org on 2026/01/14 16:00:17 UTC

(axis-axis2-c-core) 01/07: AXIS2C-1564: Add URN support to axutil_uri_parse_string

This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git

commit 913818dfbc22d13a84cb8ca4c4cc084dafb03230
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Wed Jan 14 03:42:05 2026 -1000

    AXIS2C-1564: Add URN support to axutil_uri_parse_string
    
    The URI parser was designed only for URLs (scheme://host:port/path) and
    failed to parse URNs which use a different format (urn:NID:NSS).
    
    URNs have the format "urn:<namespace-id>:<namespace-specific-string>"
    without the "://" after the scheme, and the namespace-specific string
    can contain multiple colons (e.g., urn:ietf:rfc:2648).
    
    Changes:
    - Detect URN scheme (case-insensitive "urn") before checking for "://"
    - For URNs, store "urn" as scheme and everything after "urn:" as path
    - URNs correctly have no hostname or port
    
    This enables proper interaction with systems like ebXML registry/repository
    that use URN-formatted status codes in responses.
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 util/src/uri.c            | 21 +++++++++++++++++++
 util/test/uri/uri_test.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/util/src/uri.c b/util/src/uri.c
index b5bdaaee7..df78833cb 100644
--- a/util/src/uri.c
+++ b/util/src/uri.c
@@ -390,6 +390,27 @@ axutil_uri_parse_string(
     {
         ++s;
     }
+
+    /* AXIS2C-1564: Handle URN scheme specially.
+     * URNs have format "urn:<NID>:<NSS>" without "://" after the scheme.
+     * For example: urn:ietf:rfc:2648
+     */
+    if(s != uri_str && s[0] == ':' && (s - uri_str == 3) &&
+       (uri_str[0] == 'u' || uri_str[0] == 'U') &&
+       (uri_str[1] == 'r' || uri_str[1] == 'R') &&
+       (uri_str[2] == 'n' || uri_str[2] == 'N'))
+    {
+        /* This is a URN - store scheme and path, no host/port */
+        uri->scheme = axutil_strmemdup(uri_str, s - uri_str, env);
+        ++s; /* skip the colon */
+        /* Store the rest (NID:NSS) as the path */
+        if(*s != '\0')
+        {
+            uri->path = axutil_strdup(env, s);
+        }
+        goto end;
+    }
+
     /* scheme must be non-empty and followed by :// */
     if(s == uri_str || s[0] != ':' || s[1] != '/' || s[2] != '/')
     {
diff --git a/util/test/uri/uri_test.cc b/util/test/uri/uri_test.cc
index d31013fb8..cfd7c3fdb 100644
--- a/util/test/uri/uri_test.cc
+++ b/util/test/uri/uri_test.cc
@@ -115,3 +115,55 @@ TEST_F(TestURI, test_uri)
     axutil_uri_free(base, m_env);
     axutil_uri_free(hostinfo, m_env);
 }
+
+/* AXIS2C-1564: Test URN parsing
+ * URNs have format urn:<NID>:<NSS> without "://" after the scheme
+ */
+TEST_F(TestURI, test_urn_parsing)
+{
+    axutil_uri_t *uri = NULL;
+    axis2_char_t *str;
+
+    /* Test basic URN */
+    uri = axutil_uri_parse_string(m_env, "urn:ietf:rfc:2648");
+    ASSERT_NE(uri, nullptr) << "Failed to parse URN urn:ietf:rfc:2648";
+
+    str = axutil_uri_get_protocol(uri, m_env);
+    ASSERT_STREQ(str, "urn") << "URN scheme should be 'urn'";
+
+    str = axutil_uri_get_path(uri, m_env);
+    ASSERT_STREQ(str, "ietf:rfc:2648") << "URN path should be 'ietf:rfc:2648'";
+
+    /* URN should not have host or port */
+    str = axutil_uri_get_host(uri, m_env);
+    ASSERT_EQ(str, nullptr) << "URN should not have host";
+
+    axis2_port_t port = axutil_uri_get_port(uri, m_env);
+    ASSERT_EQ(port, 0) << "URN should not have port";
+
+    axutil_uri_free(uri, m_env);
+
+    /* Test URN with uppercase */
+    uri = axutil_uri_parse_string(m_env, "URN:ISBN:0451450523");
+    ASSERT_NE(uri, nullptr) << "Failed to parse URN URN:ISBN:0451450523";
+
+    str = axutil_uri_get_protocol(uri, m_env);
+    ASSERT_STREQ(str, "URN") << "URN scheme should be 'URN'";
+
+    str = axutil_uri_get_path(uri, m_env);
+    ASSERT_STREQ(str, "ISBN:0451450523") << "URN path should be 'ISBN:0451450523'";
+
+    axutil_uri_free(uri, m_env);
+
+    /* Test URN with ebXML registry status (the original issue case) */
+    uri = axutil_uri_parse_string(m_env, "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success");
+    ASSERT_NE(uri, nullptr) << "Failed to parse ebXML URN";
+
+    str = axutil_uri_get_protocol(uri, m_env);
+    ASSERT_STREQ(str, "urn");
+
+    str = axutil_uri_get_path(uri, m_env);
+    ASSERT_STREQ(str, "oasis:names:tc:ebxml-regrep:ResponseStatusType:Success");
+
+    axutil_uri_free(uri, m_env);
+}