From 338706c2420ce3e51b546a6ba2574e10346a511b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 17 Jan 2018 22:49:37 -0800 Subject: fixes #211 Restore handling of '*' in URL logic --- src/core/url.c | 14 ++++++++++++++ src/supplemental/http/http.h | 8 ++++++-- src/transport/tcp/tcp.c | 3 +-- src/transport/tls/tls.c | 3 +-- 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/url.c b/src/core/url.c index 7e1b61b5..1c3d6c83 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -283,6 +283,20 @@ nni_url_parse(nni_url **urlp, const char *raw) } } + // If the hostname part is just '*', skip over it. (We treat it + // as an empty host for legacy nanomsg compatibility. This may be + // non-RFC compliant, but we're really only interested in parsing + // nanomsg URLs. One weird side effect of this is that some URLS + // which would be invalid (ipc://*/bogus for example) will now parse + // to something that might be surprising (ipc:///bogus now), for + // example -- although in the IPC case the URL is *always* a local + // path without any host component. + if (((len == 1) && (s[0] == '*')) || + ((len > 1) && (strncmp(s, "*:", 2) == 0))) { + s++; + len--; + } + if ((url->u_host = nni_alloc(len + 1)) == NULL) { rv = NNG_ENOMEM; goto error; diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h index 47c8d654..4e2ac697 100644 --- a/src/supplemental/http/http.h +++ b/src/supplemental/http/http.h @@ -134,8 +134,12 @@ enum { NNI_HTTP_STATUS_CONTINUE = 100, // the connection. typedef struct nni_http nni_http; -extern int nni_http_init_tcp(nni_http **, void *); -extern int nni_http_init_tls(nni_http **, nng_tls_config *, void *); +// These initialization functions create stream for HTTP transactions. +// They should only be used by the server or client HTTP implementations, +// and are not for use by other code. +extern int nni_http_init_tcp(nni_http **, void *); +extern int nni_http_init_tls(nni_http **, nng_tls_config *, void *); + extern void nni_http_close(nni_http *); extern void nni_http_fini(nni_http *); diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index a361da53..9110e31c 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -564,8 +564,7 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) return (rv); } - if ((strlen(url->u_hostname) == 0) || - (strcmp(url->u_hostname, "*") == 0)) { + if (strlen(url->u_hostname) == 0) { host = NULL; } else { host = url->u_hostname; diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index 9832c36c..753a1e75 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -580,8 +580,7 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) return (rv); } - if ((strlen(url->u_hostname) == 0) || - (strcmp(url->u_hostname, "*") == 0)) { + if (strlen(url->u_hostname) == 0) { host = NULL; } else { host = url->u_hostname; -- cgit v1.2.3-70-g09d2