From 79afcea91aa6882eede47b5cddc4f097454b6027 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 8 Aug 2020 14:02:52 -0700 Subject: fixes #1279 Add support for ws4:// and ws6:// style websocket urls fixes #1277 FreeBSD errors due to bad v4 vs. v6 assumptions --- src/core/stream.c | 16 ++++++++++++++-- src/supplemental/http/http_server.c | 8 ++++++++ src/transport/ws/websocket.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/stream.c b/src/core/stream.c index e7ebc4e0..2112f5ef 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -74,7 +74,19 @@ static struct { .listener_alloc = nni_ws_listener_alloc, .checkopt = nni_ws_checkopt, }, - { + { + .scheme = "ws4", + .dialer_alloc = nni_ws_dialer_alloc, + .listener_alloc = nni_ws_listener_alloc, + .checkopt = nni_ws_checkopt, + }, + { + .scheme = "ws6", + .dialer_alloc = nni_ws_dialer_alloc, + .listener_alloc = nni_ws_listener_alloc, + .checkopt = nni_ws_checkopt, + }, + { .scheme = "wss", .dialer_alloc = nni_ws_dialer_alloc, .listener_alloc = nni_ws_listener_alloc, diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index e711c2a2..caa06b3d 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -937,6 +937,14 @@ http_server_init(nni_http_server **serverp, const nni_url *url) } else if ((strcmp(url->u_scheme, "https") == 0) || (strcmp(url->u_scheme, "wss") == 0)) { myurl.u_scheme = "tls+tcp"; + } else if (strcmp(url->u_scheme, "ws4") == 0) { + myurl.u_scheme = "tcp4"; + } else if (strcmp(url->u_scheme, "ws6") == 0) { + myurl.u_scheme = "tcp6"; + } else if (strcmp(url->u_scheme, "wss4") == 0) { + myurl.u_scheme = "tls+tcp4"; + } else if (strcmp(url->u_scheme, "wss6") == 0) { + myurl.u_scheme = "tls+tcp6"; } else { return (NNG_EADDRINVAL); } diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index e2578f32..545a519d 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -670,10 +670,40 @@ static nni_tran ws_tran = { .tran_checkopt = wstran_checkopt, }; +static nni_tran ws4_tran = { + .tran_version = NNI_TRANSPORT_VERSION, + .tran_scheme = "ws4", + .tran_dialer = &ws_dialer_ops, + .tran_listener = &ws_listener_ops, + .tran_pipe = &ws_pipe_ops, + .tran_init = wstran_init, + .tran_fini = wstran_fini, + .tran_checkopt = wstran_checkopt, +}; + +static nni_tran ws6_tran = { + .tran_version = NNI_TRANSPORT_VERSION, + .tran_scheme = "ws6", + .tran_dialer = &ws_dialer_ops, + .tran_listener = &ws_listener_ops, + .tran_pipe = &ws_pipe_ops, + .tran_init = wstran_init, + .tran_fini = wstran_fini, + .tran_checkopt = wstran_checkopt, +}; + + int nng_ws_register(void) { - return (nni_tran_register(&ws_tran)); + int rv; + if (((rv = nni_tran_register(&ws_tran)) != 0) || + ((rv = nni_tran_register(&ws4_tran)) != 0) || + ((rv = nni_tran_register(&ws6_tran)) != 0)) { + return (rv); + } + + return (0); } #ifdef NNG_TRANSPORT_WSS -- cgit v1.2.3-70-g09d2