diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-01-22 14:05:10 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-01-22 17:11:58 -0800 |
| commit | 3d075fad7496ec126c5087d1c36ab7a4af73ce16 (patch) | |
| tree | c5b5d6fe44eaa2996310683b5080de87160b9b41 /src/transport | |
| parent | 5b1a3af7be4ae712868ae84b9a7d5a974d272b16 (diff) | |
| download | nng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.tar.gz nng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.tar.bz2 nng-3d075fad7496ec126c5087d1c36ab7a4af73ce16.zip | |
fixes #219 transports should take URL structure instead of string address
This eliminates a bunch of redundant URL parsing, using the common
URL logic we already have in place.
While here I fixed a problem with the TLS and WSS test suites that
was failing on older Ubuntu -- apparently older versions of mbedTLS
were unhappy if selecting OPTIONAL verification without a validate
certificate chain.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/inproc/inproc.c | 11 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.c | 11 | ||||
| -rw-r--r-- | src/transport/tcp/tcp.c | 13 | ||||
| -rw-r--r-- | src/transport/tls/tls.c | 17 | ||||
| -rw-r--r-- | src/transport/ws/websocket.c | 9 | ||||
| -rw-r--r-- | src/transport/zerotier/zerotier.c | 13 |
6 files changed, 16 insertions, 58 deletions
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 5b52e80a..4cd1c97d 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -47,7 +47,7 @@ struct nni_inproc_pair { }; struct nni_inproc_ep { - char addr[NNG_MAXADDRLEN + 1]; + const char * addr; int mode; nni_list_node node; uint16_t proto; @@ -190,13 +190,10 @@ nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) } static int -nni_inproc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +nni_inproc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_inproc_ep *ep; - if (strlen(url) > NNG_MAXADDRLEN - 1) { - return (NNG_EINVAL); - } if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } @@ -206,8 +203,8 @@ nni_inproc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) NNI_LIST_INIT(&ep->clients, nni_inproc_ep, node); nni_aio_list_init(&ep->aios); - (void) snprintf(ep->addr, sizeof(ep->addr), "%s", url); - *epp = ep; + ep->addr = url->u_rawurl; // we match on the full URL. + *epp = ep; return (0); } diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 84292bb8..62751d86 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -529,17 +529,16 @@ nni_ipc_ep_fini(void *arg) } static int -nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_ipc_ep *ep; int rv; size_t sz; - if (strncmp(url, "ipc://", strlen("ipc://")) != 0) { - return (NNG_EADDRINVAL); + if (((url->u_host != NULL) && (strlen(url->u_host) > 0)) || + (url->u_userinfo != NULL)) { + return (NNG_EINVAL); } - url += strlen("ipc://"); - if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } @@ -547,7 +546,7 @@ nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) sz = sizeof(ep->sa.s_un.s_path.sa_path); ep->sa.s_un.s_path.sa_family = NNG_AF_IPC; - if (nni_strlcpy(ep->sa.s_un.s_path.sa_path, url, sz) >= sz) { + if (nni_strlcpy(ep->sa.s_un.s_path.sa_path, url->u_path, sz) >= sz) { NNI_FREE_STRUCT(ep); return (NNG_EADDRINVAL); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 9110e31c..0a123a79 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -527,14 +527,13 @@ nni_tcp_ep_fini(void *arg) if (ep->tep != NULL) { nni_plat_tcp_ep_fini(ep->tep); } - nni_url_free(ep->url); nni_aio_fini(ep->aio); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); } static int -nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) +nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_tcp_ep * ep; int rv; @@ -543,24 +542,17 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_sockaddr rsa, lsa; nni_aio * aio; int passive; - nni_url * url; - if ((rv = nni_url_parse(&url, addr)) != 0) { - return (rv); - } // Check for invalid URL components. if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((url->u_fragment != NULL) || (url->u_userinfo != NULL) || (url->u_query != NULL)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - nni_url_free(url); return (rv); } @@ -582,7 +574,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) lsa.s_un.s_family = NNG_AF_UNSPEC; aio->a_addr = &rsa; if ((host == NULL) || (serv == NULL)) { - nni_url_free(url); nni_aio_fini(aio); return (NNG_EADDRINVAL); } @@ -595,7 +586,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_plat_tcp_resolv(host, serv, NNG_AF_UNSPEC, passive, aio); nni_aio_wait(aio); if ((rv = nni_aio_result(aio)) != 0) { - nni_url_free(url); nni_aio_fini(aio); return (rv); } @@ -603,7 +593,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_aio_fini(aio); if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { - nni_url_free(url); return (NNG_ENOMEM); } nni_mtx_init(&ep->mtx); diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index 753a1e75..6bc884e7 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -537,16 +537,13 @@ nni_tls_ep_fini(void *arg) if (ep->cfg) { nni_tls_config_fini(ep->cfg); } - if (ep->url) { - nni_url_free(ep->url); - } nni_aio_fini(ep->aio); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); } static int -nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) +nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_tls_ep * ep; int rv; @@ -557,26 +554,17 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) int passive; nng_tls_mode tlsmode; nng_tls_auth_mode authmode; - nni_url * url; - - // Parse the URLs first. - if ((rv = nni_url_parse(&url, addr)) != 0) { - return (rv); - } // Check for invalid URL components. if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((url->u_fragment != NULL) || (url->u_userinfo != NULL) || (url->u_query != NULL)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - nni_url_free(url); return (rv); } @@ -598,7 +586,6 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) lsa.s_un.s_family = NNG_AF_UNSPEC; aio->a_addr = &rsa; if ((host == NULL) || (serv == NULL)) { - nni_url_free(url); nni_aio_fini(aio); return (NNG_EADDRINVAL); } @@ -615,14 +602,12 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_plat_tcp_resolv(host, serv, NNG_AF_UNSPEC, passive, aio); nni_aio_wait(aio); if ((rv = nni_aio_result(aio)) != 0) { - nni_url_free(url); nni_aio_fini(aio); return (rv); } nni_aio_fini(aio); if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { - nni_url_free(url); return (NNG_ENOMEM); } nni_mtx_init(&ep->mtx); diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index 4db4bc72..aead6f59 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -30,8 +30,7 @@ typedef struct ws_hdr { } ws_hdr; struct ws_ep { - int mode; // NNI_EP_MODE_DIAL or NNI_EP_MODE_LISTEN - char * addr; + int mode; // NNI_EP_MODE_DIAL or NNI_EP_MODE_LISTEN uint16_t lproto; // local protocol uint16_t rproto; // remote protocol size_t rcvmax; @@ -605,7 +604,6 @@ ws_ep_fini(void *arg) nni_strfree(hdr->value); NNI_FREE_STRUCT(hdr); } - nni_strfree(ep->addr); nni_strfree(ep->protoname); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); @@ -694,7 +692,7 @@ ws_ep_acc_cb(void *arg) } static int -ws_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +ws_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { ws_ep * ep; const char *pname; @@ -721,9 +719,6 @@ ws_ep_init(void **epp, const char *url, nni_sock *sock, int mode) rv = nni_ws_listener_init(&ep->listener, url); } - if ((rv == 0) && ((ep->addr = nni_strdup(url)) == NULL)) { - rv = NNG_ENOMEM; - } if ((rv != 0) || ((rv = nni_aio_init(&ep->connaio, ws_ep_conn_cb, ep)) != 0) || ((rv = nni_aio_init(&ep->accaio, ws_ep_acc_cb, ep)) != 0) || diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index cef31a29..2522138f 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -225,7 +225,6 @@ struct zt_creq { struct zt_ep { nni_list_node ze_link; - char ze_url[NNG_MAXADDRLEN]; char ze_home[NNG_MAXADDRLEN]; // should be enough zt_node * ze_ztn; uint64_t ze_nwid; @@ -2100,7 +2099,7 @@ zt_parsedec(const char **sp, uint64_t *valp) } static int -zt_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +zt_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { zt_ep * ep; size_t sz; @@ -2127,24 +2126,18 @@ zt_ep_init(void **epp, const char *url, nni_sock *sock, int mode) ep->ze_ping_count = zt_ping_count; ep->ze_ping_time = zt_ping_time; ep->ze_proto = nni_sock_proto(sock); - sz = sizeof(ep->ze_url); nni_aio_list_init(&ep->ze_aios); - if ((strncmp(url, "zt://", strlen("zt://")) != 0) || - (nni_strlcpy(ep->ze_url, url, sz) >= sz)) { - zt_ep_fini(ep); - return (NNG_EADDRINVAL); - } rv = nni_aio_init(&ep->ze_creq_aio, zt_ep_conn_req_cb, ep); if (rv != 0) { zt_ep_fini(ep); return (rv); } - u = url + strlen("zt://"); - // Parse the URL. + u = url->u_rawurl + strlen("zt://"); + // Parse the URL. switch (mode) { case NNI_EP_MODE_DIAL: // We require zt://<nwid>/<remotenode>:<port> |
