From cef6e70c0b3e92e36b6895e7d6e981b00c702f9b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 22 Nov 2024 18:16:24 -0800 Subject: Select transport using raw URL string. This is done so that we can provide transport specific logic for URL parsing later (we're going to want this for ZeroTier for example.) --- src/core/dialer.c | 10 +++++----- src/core/listener.c | 11 +++++------ src/sp/transport.c | 6 ++++-- src/sp/transport.h | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/core/dialer.c b/src/core/dialer.c index 27020b37..3cd6620f 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -219,15 +219,15 @@ nni_dialer_create(nni_dialer **dp, nni_sock *s, const char *url_str) if ((d = NNI_ALLOC_STRUCT(d)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_url_parse_inline(&d->d_url, url_str)) != 0) { + if (((tran = nni_sp_tran_find(url_str)) == NULL) || + (tran->tran_dialer == NULL)) { NNI_FREE_STRUCT(d); - return (rv); + return (NNG_ENOTSUP); } - if (((tran = nni_sp_tran_find(&d->d_url)) == NULL) || - (tran->tran_dialer == NULL)) { + if ((rv = nni_url_parse_inline(&d->d_url, url_str)) != 0) { nni_url_fini(&d->d_url); NNI_FREE_STRUCT(d); - return (NNG_ENOTSUP); + return (rv); } d->d_closed = false; d->d_data = NULL; diff --git a/src/core/listener.c b/src/core/listener.c index 08b235af..3c2d7bf0 100644 --- a/src/core/listener.c +++ b/src/core/listener.c @@ -207,16 +207,15 @@ nni_listener_create(nni_listener **lp, nni_sock *s, const char *url_str) if ((l = NNI_ALLOC_STRUCT(l)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_url_parse_inline(&l->l_url, url_str)) != 0) { - nni_url_fini(&l->l_url); + if (((tran = nni_sp_tran_find(url_str)) == NULL) || + (tran->tran_listener == NULL)) { NNI_FREE_STRUCT(l); - return (rv); + return (NNG_ENOTSUP); } - if (((tran = nni_sp_tran_find(&l->l_url)) == NULL) || - (tran->tran_listener == NULL)) { + if ((rv = nni_url_parse_inline(&l->l_url, url_str)) != 0) { nni_url_fini(&l->l_url); NNI_FREE_STRUCT(l); - return (NNG_ENOTSUP); + return (rv); } l->l_closed = false; l->l_data = NULL; diff --git a/src/sp/transport.c b/src/sp/transport.c index 61192e82..a2220e7b 100644 --- a/src/sp/transport.c +++ b/src/sp/transport.c @@ -32,14 +32,16 @@ nni_sp_tran_register(nni_sp_tran *tran) } nni_sp_tran * -nni_sp_tran_find(nng_url *url) +nni_sp_tran_find(const char *url) { // address is of the form "://blah..." nni_sp_tran *t; nni_rwlock_rdlock(&sp_tran_lk); NNI_LIST_FOREACH (&sp_tran_list, t) { - if (strcmp(url->u_scheme, t->tran_scheme) == 0) { + size_t len = strlen(t->tran_scheme); + if ((strncmp(url, t->tran_scheme, len) == 0) && + (strncmp(url + len, "://", 3) == 0)) { nni_rwlock_unlock(&sp_tran_lk); return (t); } diff --git a/src/sp/transport.h b/src/sp/transport.h index 7311638f..b65486ed 100644 --- a/src/sp/transport.h +++ b/src/sp/transport.h @@ -186,7 +186,7 @@ struct nni_sp_tran { // These APIs are used by the framework internally, and not for use by // transport implementations. -extern nni_sp_tran *nni_sp_tran_find(nng_url *); +extern nni_sp_tran *nni_sp_tran_find(const char *); extern void nni_sp_tran_sys_init(void); extern void nni_sp_tran_sys_fini(void); extern void nni_sp_tran_register(nni_sp_tran *); -- cgit v1.2.3-70-g09d2