aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-18 18:49:01 -0800
committerGarrett D'Amore <garrett@damore.org>2024-11-18 18:49:01 -0800
commit143b6322f8217cfdbef8f3171d55d10348d1be37 (patch)
tree60eef8b31cf320c97c1affbbf80a968d6a63e583
parentdd4695f9492b4f30978e9043d7d6925bfe15a715 (diff)
downloadnng-143b6322f8217cfdbef8f3171d55d10348d1be37.tar.gz
nng-143b6322f8217cfdbef8f3171d55d10348d1be37.tar.bz2
nng-143b6322f8217cfdbef8f3171d55d10348d1be37.zip
Introduce accessors for nng_url struct and make it opaque.
This provides safety by ensuring that applications do not depend on the size or layout of nng_url itself.
-rw-r--r--docs/ref/api/url.md52
-rw-r--r--docs/ref/migrate/nng1.md21
-rw-r--r--include/nng/nng.h35
-rw-r--r--src/core/url.c42
-rw-r--r--src/core/url.h15
-rw-r--r--src/core/url_test.c257
6 files changed, 259 insertions, 163 deletions
diff --git a/docs/ref/api/url.md b/docs/ref/api/url.md
index db9f3be2..62cf66fd 100644
--- a/docs/ref/api/url.md
+++ b/docs/ref/api/url.md
@@ -20,28 +20,52 @@ typedef struct nng_url {
char *u_query;
char *u_fragment;
} nng_url;
+
+const char *nng_url_scheme(const nng_url *url);
+const char *nng_url_userinfo(const nng_url *url);
+const char *nng_url_hostname(const nng_url *url);
+uint16_t nng_url_port(const nng_url *url);
+const char *nng_url_path(const nng_url *url);
+const char *nng_url_query(const nng_url *url);
+const char *nng_url_fragment(const nng_url *url):
```
### URL Fields
-Applications may access individual fields, but must not free or
-alter them, as the underlying memory is managed by the library.
+The {{i:`nng_url_scheme`}} function returns the scheme,
+without any colons or slashes. Values are lower case
+strings, like "http" or "inproc" or "tls+tcp4".
+
+The {{i:`nng_url_userinfo`}} function returns a string corresponding
+to the user component of a URL (the part before any `@` sign) if such
+a component is present, otherwise it returns `NULL`.
+
+The {{i:`nng_url_hostname`}} function returns a hostname (which might
+actually be an IP address) from the URL, if the URL corresponds to a scheme
+that uses hostnames (like "http" or "tcp"). If the URL does not (for example
+"inproc" or "ipc" URLs) then it returns `NULL`.
-Additionally applications must not depend on the size of this structure.
-Obtain one using `nng_parse_url`.
+The {{i:`nng_url_port`}} function returns the TCP or UDP port number if the URL
+corresponds to a protocol based on TCP or UDP. It returns zero otherwise.
+Note that the port number might not have been explicitly specified in the URL.
+For example, the port number associated with "http://www.example.com" is 80,
+which is the standard port number for HTTP.
+
+> [!TIP]
+> The port number returned by this is in the native machine byte order.
+> Be careful when using this with other network-oriented APIs.
-The fields of an `nng_url` object are as follows:
+The {{i:`nng_url_path`}} function returns the path component of the URL.
+This will always be non-`NULL`, but it may be empty.
-- `u_scheme`: The URL scheme, such as "http" or "inproc". Always lower case. This will never be `NULL`.
-- `u_userinfo`: This username and password if supplied in the URL string. Will be `NULL` when not present.
-- `u_hostname`: The name of the host, and may be the empty string in some cases.
-- `u_port`: The port. May be zero if irrelevant or not specified.
-- `u_path`: The path, typically used with HTTP or WebSockets. Will be empty string if not specified.
-- `u_query`: The query info (typically following `?` in the URL.) Will be `NULL` if not present.
-- `u_fragment`: This is used for specifying an anchor, the part after `#` in a URL. Will be `NULL` if not present.
+The {{i:`nng_url_query`}} and {{i:`nng_url_fragment`}} functions return
+the query-information (the part following a '?') and fragment
+(the part following a '#') if those components are present, or `NULL`
+if they are not. The returned string will not include the leading '?' or '#'
+characters.
-> [!NOTE]
-> Other fields may also be present, but only those documented here are safe for application use.
+Note that any strings returned by these functions are only valid until
+_url_ is freed with [`nng_url_free`].
## Format a URL
diff --git a/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md
index ddad9ff7..1d903215 100644
--- a/docs/ref/migrate/nng1.md
+++ b/docs/ref/migrate/nng1.md
@@ -166,14 +166,21 @@ The use of `*` to act as a wild card meaning all local interface addresses
is removed. The empty string already performs this function, and unlike
`*` is RFC compliant.
-## URL Structure Members
-
-The details of [`nng_url`] have changed as follows:
-
-- `u_port` is no longer a string, but a `uint16_t`
-- `u_scheme` is a `const char *`
+## URL Structure Changes
+
+The details of [`nng_url`] have changed significantly, and direct
+access of the structure is no longer permitted. Intead new
+accessors functions are provided:
+
+- `u_scheme` is replaced by [`nng_url_scheme`].
+- `u_port` is replaced by [`nng_url_port`], but this returns a `uint16_t`.
+- `u_hostname` is replaced by [`nng_url_hostname`].
+- `u_path` is replaced by [`nng_url_path`].
+- `u_query` is replaced by [`nng_url_query`].
+- `u_fragment` is replaced by [`nng_url_fragment`].
+- `u_userinfo` is replaced by [`nng_url_userinfo`].
- `u_requri` is removed - it can be easily formulated from the other fields.
-- `u_host` is removed - use `u_hostname` and `u_port` to construct if needed
+- `u_host` is removed - use [`nng_url_hostname`] and [`nng_url_port`] to construct if needed
- `u_rawurl` is removed - a "cooked" URL can be obtained from the new [`nng_url_sprintf`] function.
{{#include ../xref.md}}
diff --git a/include/nng/nng.h b/include/nng/nng.h
index 47260b8d..8b56d15a 100644
--- a/include/nng/nng.h
+++ b/include/nng/nng.h
@@ -1082,20 +1082,7 @@ enum nng_errno_enum {
// URL support. We frequently want to process a URL, and these methods
// give us a convenient way of doing so.
-typedef struct nng_url {
- char *u_rawurl; // never NULL
- const char *u_scheme; // never NULL
- const char *u_userinfo; // will be NULL if not specified
- char *u_hostname; // name only, will be "" if not specified
- uint16_t u_port; // port, may be zero for schemes that do not use
- char *u_path; // path, will be "" if not specified
- char *u_query; // without '?', will be NULL if not specified
- char *u_fragment; // without '#', will be NULL if not specified
- // these members are private
- char *u_buffer;
- size_t u_bufsz;
- char u_static[NNG_MAXADDRLEN]; // Most URLs fit within this
-} nng_url;
+typedef struct nng_url nng_url;
// nng_url_parse parses a URL string into a structured form.
// Note that the u_port member will be filled out with a numeric
@@ -1114,6 +1101,26 @@ NNG_DECL int nng_url_clone(nng_url **, const nng_url *);
// snprintf.
NNG_DECL int nng_url_sprintf(char *, size_t, const nng_url *);
+NNG_DECL const char *nng_url_scheme(const nng_url *);
+
+// Port (TCP) for a URL, can be zero for ports are not used by the scheme.
+NNG_DECL uint16_t nng_url_port(const nng_url *);
+
+// hostname part of URL, can be NULL if irerelvant to scheme
+const char *nng_url_hostname(const nng_url *);
+
+// user info part (thing before '@') of URL, NULL if absent.
+const char *nng_url_userinfo(const nng_url *);
+
+// path portion of URL, will always non-NULL, but may be empty.
+const char *nng_url_path(const nng_url *);
+
+// query info part of URL, not including '?, NULL if absent'
+const char *nng_url_query(const nng_url *);
+
+// fragment part of URL, not including '#', NULL if absent.
+const char *nng_url_fragment(const nng_url *);
+
// nng_version returns the library version as a human readable string.
NNG_DECL const char *nng_version(void);
diff --git a/src/core/url.c b/src/core/url.c
index 6e17e8c7..4be730cc 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -687,3 +687,45 @@ nni_url_to_address(nng_sockaddr *sa, const nng_url *url)
nni_aio_fini(&aio);
return (rv);
}
+
+const char *
+nng_url_scheme(const nng_url *url)
+{
+ return (url->u_scheme);
+}
+
+uint16_t
+nng_url_port(const nng_url *url)
+{
+ return (url->u_port);
+}
+
+const char *
+nng_url_hostname(const nng_url *url)
+{
+ return (url->u_hostname);
+}
+
+const char *
+nng_url_path(const nng_url *url)
+{
+ return (url->u_path);
+}
+
+const char *
+nng_url_query(const nng_url *url)
+{
+ return (url->u_query);
+}
+
+const char *
+nng_url_userinfo(const nng_url *url)
+{
+ return (url->u_userinfo);
+}
+
+const char *
+nng_url_fragment(const nng_url *url)
+{
+ return (url->u_fragment);
+}
diff --git a/src/core/url.h b/src/core/url.h
index 2eb3ed46..f8a141ac 100644
--- a/src/core/url.h
+++ b/src/core/url.h
@@ -13,6 +13,21 @@
#include "core/defs.h"
+struct nng_url {
+ char *u_rawurl; // never NULL
+ const char *u_scheme; // never NULL
+ const char *u_userinfo; // will be NULL if not specified
+ char *u_hostname; // name only, will be "" if not specified
+ uint16_t u_port; // port, may be zero for schemes that do not use
+ char *u_path; // path, will be "" if not specified
+ char *u_query; // without '?', will be NULL if not specified
+ char *u_fragment; // without '#', will be NULL if not specified
+ // these members are private
+ char *u_buffer;
+ size_t u_bufsz;
+ char u_static[NNG_MAXADDRLEN]; // Most URLs fit within this
+};
+
extern uint16_t nni_url_default_port(const char *);
extern int nni_url_asprintf(char **, const nng_url *);
extern int nni_url_asprintf_port(char **, const nng_url *, int);
diff --git a/src/core/url_test.c b/src/core/url_test.c
index 4b767188..182121d9 100644
--- a/src/core/url_test.c
+++ b/src/core/url_test.c
@@ -8,6 +8,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include "nng_impl.h"
#include <nuts.h>
#include <string.h>
@@ -19,13 +20,13 @@ test_url_host(void)
NUTS_PASS(nng_url_parse(&url, "http://www.google.com"));
NUTS_ASSERT(url != NULL);
- NUTS_TRUE(strcmp(url->u_scheme, "http") == 0);
- NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0);
- NUTS_TRUE(url->u_port == 80);
- NUTS_TRUE(strcmp(url->u_path, "") == 0);
- NUTS_TRUE(url->u_query == NULL);
- NUTS_TRUE(url->u_fragment == NULL);
- NUTS_TRUE(url->u_userinfo == NULL);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -49,13 +50,13 @@ test_url_host_port(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://www.google.com:1234"));
NUTS_ASSERT(url != NULL);
- NUTS_TRUE(strcmp(url->u_scheme, "http") == 0);
- NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0);
- NUTS_TRUE(url->u_port == 1234);
- NUTS_TRUE(strcmp(url->u_path, "") == 0);
- NUTS_TRUE(url->u_query == NULL);
- NUTS_TRUE(url->u_fragment == NULL);
- NUTS_TRUE(url->u_userinfo == NULL);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 1234);
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -66,13 +67,13 @@ test_url_host_port_path(void)
NUTS_PASS(nng_url_parse(&url, "http://www.google.com:1234/somewhere"));
NUTS_ASSERT(url != NULL);
- NUTS_TRUE(strcmp(url->u_scheme, "http") == 0);
- NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0);
- NUTS_TRUE(url->u_port == 1234);
- NUTS_TRUE(strcmp(url->u_path, "/somewhere") == 0);
- NUTS_TRUE(url->u_userinfo == NULL);
- NUTS_TRUE(url->u_query == NULL);
- NUTS_TRUE(url->u_fragment == NULL);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 1234);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_NULL(nng_url_userinfo(url));
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
nng_url_free(url);
}
@@ -83,13 +84,13 @@ test_url_user_info(void)
NUTS_PASS(nng_url_parse(
&url, "http://garrett@www.google.com:1234/somewhere"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_userinfo, "garrett");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_TRUE(url->u_port == 1234);
- NUTS_MATCH(url->u_path, "/somewhere");
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_userinfo(url), "garrett");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 1234);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
nng_url_free(url);
}
@@ -100,13 +101,13 @@ test_url_path_query_param(void)
NUTS_PASS(
nng_url_parse(&url, "http://www.google.com/somewhere?result=yes"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/somewhere");
- NUTS_MATCH(url->u_query, "result=yes");
- NUTS_NULL(url->u_userinfo);
- NUTS_NULL(url->u_fragment);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_MATCH(nng_url_query(url), "result=yes");
+ NUTS_NULL(nng_url_userinfo(url));
+ NUTS_NULL(nng_url_fragment(url));
nng_url_free(url);
}
@@ -118,13 +119,13 @@ test_url_query_param_anchor(void)
"http://www.google.com/"
"somewhere?result=yes#chapter1"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/somewhere");
- NUTS_MATCH(url->u_query, "result=yes");
- NUTS_MATCH(url->u_fragment, "chapter1");
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_MATCH(nng_url_query(url), "result=yes");
+ NUTS_MATCH(nng_url_fragment(url), "chapter1");
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -139,13 +140,13 @@ test_url_clone(void)
NUTS_ASSERT(src != NULL);
NUTS_PASS(nng_url_clone(&url, src));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/somewhere");
- NUTS_MATCH(url->u_query, "result=yes");
- NUTS_MATCH(url->u_fragment, "chapter1");
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_MATCH(nng_url_query(url), "result=yes");
+ NUTS_MATCH(nng_url_fragment(url), "chapter1");
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
nng_url_free(src);
}
@@ -157,13 +158,13 @@ test_url_path_anchor(void)
NUTS_PASS(
nng_url_parse(&url, "http://www.google.com/somewhere#chapter2"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/somewhere");
- NUTS_MATCH(url->u_fragment, "chapter2");
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/somewhere");
+ NUTS_MATCH(nng_url_fragment(url), "chapter2");
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -173,13 +174,13 @@ test_url_anchor(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://www.google.com#chapter3"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_fragment, "chapter3");
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_fragment(url), "chapter3");
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -189,13 +190,13 @@ test_url_query_param(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://www.google.com?color=red"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.google.com");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_query, "color=red");
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.google.com");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_query(url), "color=red");
NUTS_ASSERT(url != NULL);
- NUTS_NULL(url->u_userinfo);
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -205,13 +206,13 @@ test_url_v6_host(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://[::1]"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "::1");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 80);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "::1");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -221,13 +222,13 @@ test_url_v6_host_port(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://[::1]:29"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "::1");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 29);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "::1");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 29);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -237,13 +238,13 @@ test_url_v6_host_port_path(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "http://[::1]:29/bottles"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "::1");
- NUTS_MATCH(url->u_path, "/bottles");
- NUTS_TRUE(url->u_port == 29);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "::1");
+ NUTS_MATCH(nng_url_path(url), "/bottles");
+ NUTS_TRUE(nng_url_port(url) == 29);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -253,13 +254,13 @@ test_url_tcp_port(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "tcp://:9876/"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "tcp");
- NUTS_MATCH(url->u_hostname, "");
- NUTS_MATCH(url->u_path, "/");
- NUTS_TRUE(url->u_port == 9876);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "tcp");
+ NUTS_MATCH(nng_url_hostname(url), "");
+ NUTS_MATCH(nng_url_path(url), "/");
+ NUTS_TRUE(nng_url_port(url) == 9876);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -270,13 +271,13 @@ test_url_bare_ws(void)
NUTS_PASS(nng_url_parse(&url, "ws://"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "ws");
- NUTS_MATCH(url->u_hostname, "");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 80);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_NULL(url->u_userinfo);
+ NUTS_MATCH(nng_url_scheme(url), "ws");
+ NUTS_MATCH(nng_url_hostname(url), "");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_NULL(nng_url_userinfo(url));
nng_url_free(url);
}
@@ -286,13 +287,13 @@ test_url_ssh(void)
nng_url *url;
NUTS_PASS(nng_url_parse(&url, "ssh://user@host.example.com"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "ssh");
- NUTS_MATCH(url->u_hostname, "host.example.com");
- NUTS_MATCH(url->u_path, "");
- NUTS_TRUE(url->u_port == 22);
- NUTS_NULL(url->u_query);
- NUTS_NULL(url->u_fragment);
- NUTS_MATCH(url->u_userinfo, "user");
+ NUTS_MATCH(nng_url_scheme(url), "ssh");
+ NUTS_MATCH(nng_url_hostname(url), "host.example.com");
+ NUTS_MATCH(nng_url_path(url), "");
+ NUTS_TRUE(nng_url_port(url) == 22);
+ NUTS_NULL(nng_url_query(url));
+ NUTS_NULL(nng_url_fragment(url));
+ NUTS_MATCH(nng_url_userinfo(url), "user");
nng_url_free(url);
}
@@ -325,10 +326,10 @@ test_url_canonify(void)
NUTS_PASS(nng_url_parse(
&url, "http://www.EXAMPLE.com/bogus/.%2e/%7egarrett"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.example.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/~garrett");
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.example.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/~garrett");
nng_url_free(url);
}
@@ -338,10 +339,10 @@ test_url_path_resolve(void)
nng_url *url = NULL;
NUTS_PASS(
nng_url_parse(&url, "http://www.x.com//abc/def/./x/..///./../y"));
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.x.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/abc/y");
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.x.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/abc/y");
nng_url_free(url);
}
@@ -352,11 +353,11 @@ test_url_query_info_pass(void)
NUTS_PASS(
nng_url_parse(&url, "http://www.x.com/?/abc/def/./x/.././../y"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.x.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/");
- NUTS_MATCH(url->u_query, "/abc/def/./x/.././../y");
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.x.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/");
+ NUTS_MATCH(nng_url_query(url), "/abc/def/./x/.././../y");
nng_url_free(url);
}
@@ -376,10 +377,10 @@ test_url_good_utf8(void)
nng_url *url = NULL;
NUTS_PASS(nng_url_parse(&url, "http://www.x.com/%c2%a2_cents"));
NUTS_ASSERT(url != NULL);
- NUTS_MATCH(url->u_scheme, "http");
- NUTS_MATCH(url->u_hostname, "www.x.com");
- NUTS_TRUE(url->u_port == 80);
- NUTS_MATCH(url->u_path, "/\xc2\xa2_cents");
+ NUTS_MATCH(nng_url_scheme(url), "http");
+ NUTS_MATCH(nng_url_hostname(url), "www.x.com");
+ NUTS_TRUE(nng_url_port(url) == 80);
+ NUTS_MATCH(nng_url_path(url), "/\xc2\xa2_cents");
nng_url_free(url);
}