aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-22 18:43:13 -0800
committerGarrett D'Amore <garrett@damore.org>2024-11-22 18:43:13 -0800
commitdacb9629b9161cbd09de533842bb05ee0b0cad48 (patch)
treede0c8a70440c3f7e8dea5763e5a6d4a3aef32284 /src
parentcef6e70c0b3e92e36b6895e7d6e981b00c702f9b (diff)
downloadnng-dacb9629b9161cbd09de533842bb05ee0b0cad48.tar.gz
nng-dacb9629b9161cbd09de533842bb05ee0b0cad48.tar.bz2
nng-dacb9629b9161cbd09de533842bb05ee0b0cad48.zip
Fix socket:// hostname should be null, and add test case
Diffstat (limited to 'src')
-rw-r--r--src/core/url.c12
-rw-r--r--src/sp/transport/socket/sockfd.c2
-rw-r--r--src/sp/transport/socket/sockfd_test.c15
3 files changed, 23 insertions, 6 deletions
diff --git a/src/core/url.c b/src/core/url.c
index e436b0e1..c4bda443 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -390,8 +390,13 @@ nni_url_parse_inline(nng_url *url, const char *raw)
if ((strcmp(url->u_scheme, "ipc") == 0) ||
(strcmp(url->u_scheme, "unix") == 0) ||
(strcmp(url->u_scheme, "abstract") == 0) ||
- (strcmp(url->u_scheme, "inproc") == 0)) {
- url->u_path = p;
+ (strcmp(url->u_scheme, "inproc") == 0) ||
+ (strcmp(url->u_scheme, "socket") == 0)) {
+ url->u_path = p;
+ url->u_hostname = NULL;
+ url->u_query = NULL;
+ url->u_fragment = NULL;
+ url->u_userinfo = NULL;
return (0);
}
@@ -553,7 +558,8 @@ nng_url_sprintf(char *str, size_t size, const nng_url *url)
if ((strcmp(scheme, "ipc") == 0) || (strcmp(scheme, "inproc") == 0) ||
(strcmp(scheme, "unix") == 0) ||
- (strcmp(scheme, "abstract") == 0)) {
+ (strcmp(scheme, "abstract") == 0) ||
+ (strcmp(scheme, "socket") == 0)) {
return (snprintf(str, size, "%s://%s", scheme, url->u_path));
}
diff --git a/src/sp/transport/socket/sockfd.c b/src/sp/transport/socket/sockfd.c
index 03706be8..d3d4218f 100644
--- a/src/sp/transport/socket/sockfd.c
+++ b/src/sp/transport/socket/sockfd.c
@@ -818,7 +818,7 @@ sfd_tran_listener_init(void **lp, nng_url *url, nni_listener *nlistener)
nni_sock *sock = nni_listener_sock(nlistener);
// Check for invalid URL components -- we only accept a bare scheme
- if ((strlen(url->u_hostname) != 0) || (strlen(url->u_path) != 0) ||
+ if ((url->u_hostname != NULL) || (strlen(url->u_path) != 0) ||
(url->u_fragment != NULL) || (url->u_userinfo != NULL) ||
(url->u_query != NULL)) {
return (NNG_EADDRINVAL);
diff --git a/src/sp/transport/socket/sockfd_test.c b/src/sp/transport/socket/sockfd_test.c
index 842a377c..c27f49bd 100644
--- a/src/sp/transport/socket/sockfd_test.c
+++ b/src/sp/transport/socket/sockfd_test.c
@@ -10,6 +10,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include <nng/nng.h>
#include <nuts.h>
#ifdef NNG_PLATFORM_POSIX
@@ -50,10 +51,20 @@ test_sfd_malformed_address(void)
void
test_sfd_listen(void)
{
- nng_socket s1;
+ nng_socket s1;
+ nng_listener l;
+ const nng_url *u;
NUTS_OPEN(s1);
- NUTS_PASS(nng_listen(s1, "socket://", NULL, 0));
+ NUTS_PASS(nng_listen(s1, "socket://", &l, 0));
+ NUTS_PASS(nng_listener_get_url(l, &u));
+ NUTS_MATCH(nng_url_scheme(u), "socket");
+ NUTS_MATCH(nng_url_path(u), "");
+ NUTS_NULL(nng_url_userinfo(u));
+ NUTS_NULL(nng_url_hostname(u));
+ NUTS_NULL(nng_url_query(u));
+ NUTS_NULL(nng_url_fragment(u));
+
NUTS_CLOSE(s1);
}