aboutsummaryrefslogtreecommitdiff
path: root/src/transport/ws
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-12-29 21:28:49 -0800
committerGarrett D'Amore <garrett@damore.org>2018-12-31 17:10:04 -0800
commita73ff5363eae228009413872b05aff758a46c5ca (patch)
treed5fa805188f915fc94c9b80d4f5cbbb96e6a4551 /src/transport/ws
parente0fff1f9c45f5486fc2e7eeb49b4462c3bb2dad4 (diff)
downloadnng-a73ff5363eae228009413872b05aff758a46c5ca.tar.gz
nng-a73ff5363eae228009413872b05aff758a46c5ca.tar.bz2
nng-a73ff5363eae228009413872b05aff758a46c5ca.zip
fixes #825 TCP public API should use generic setopt/getopt
This changes much of the internal API for TCP option handling, and includes hooks for some of this in various consumers. Note that the consumers still need to have additional work done to complete them, which will be part of providing public "raw" TLS and WebSocket APIs. We would also like to finish addressing the call sites of nni_tcp_listener_start() that assume the sockaddr is modified -- it would be superior to use the NNG_OPT_LOCADDR option. Thaat will be addressed in a follow up PR.
Diffstat (limited to 'src/transport/ws')
-rw-r--r--src/transport/ws/websocket.c83
1 files changed, 24 insertions, 59 deletions
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index 1d5358f6..bf10f7e0 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -1,6 +1,7 @@
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Devolutions <info@devolutions.net>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -14,12 +15,12 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "nng/supplemental/tls/tls.h"
#include "supplemental/http/http_api.h"
#include "supplemental/tls/tls_api.h"
#include "supplemental/websocket/websocket.h"
-#include "nng/transport/ws/websocket.h"
+#include <nng/supplemental/tls/tls.h>
+#include <nng/transport/ws/websocket.h>
typedef struct ws_dialer ws_dialer;
typedef struct ws_listener ws_listener;
@@ -577,34 +578,6 @@ ws_listener_set_reshdrs(void *arg, const void *v, size_t sz, nni_opt_type t)
}
static int
-ws_pipe_get_locaddr(void *arg, void *v, size_t *szp, nni_opt_type t)
-{
- ws_pipe * p = arg;
- int rv;
- nni_sockaddr sa;
-
- memset(&sa, 0, sizeof(sa));
- if ((rv = nni_ws_sock_addr(p->ws, &sa)) == 0) {
- rv = nni_copyout_sockaddr(&sa, v, szp, t);
- }
- return (rv);
-}
-
-static int
-ws_pipe_get_remaddr(void *arg, void *v, size_t *szp, nni_opt_type t)
-{
- ws_pipe * p = arg;
- int rv;
- nni_sockaddr sa;
-
- memset(&sa, 0, sizeof(sa));
- if ((rv = nni_ws_peer_addr(p->ws, &sa)) == 0) {
- rv = nni_copyout_sockaddr(&sa, v, szp, t);
- }
- return (rv);
-}
-
-static int
ws_pipe_get_reshdrs(void *arg, void *v, size_t *szp, nni_opt_type t)
{
ws_pipe * p = arg;
@@ -628,23 +601,7 @@ ws_pipe_get_reqhdrs(void *arg, void *v, size_t *szp, nni_opt_type t)
return (nni_copyout_str(s, v, szp, t));
}
-static int
-ws_pipe_get_tls_verified(void *arg, void *v, size_t *szp, nni_opt_type t)
-{
- ws_pipe *p = arg;
- return (nni_copyout_bool(nni_ws_tls_verified(p->ws), v, szp, t));
-}
-
-static nni_option ws_pipe_options[] = {
-
- {
- .o_name = NNG_OPT_LOCADDR,
- .o_get = ws_pipe_get_locaddr,
- },
- {
- .o_name = NNG_OPT_REMADDR,
- .o_get = ws_pipe_get_remaddr,
- },
+static const nni_option ws_pipe_options[] = {
{
.o_name = NNG_OPT_WS_REQUEST_HEADERS,
.o_get = ws_pipe_get_reqhdrs,
@@ -653,25 +610,33 @@ static nni_option ws_pipe_options[] = {
.o_name = NNG_OPT_WS_RESPONSE_HEADERS,
.o_get = ws_pipe_get_reshdrs,
},
- {
- .o_name = NNG_OPT_TLS_VERIFIED,
- .o_get = ws_pipe_get_tls_verified,
- },
// terminate list
{
.o_name = NULL,
}
};
+static int
+ws_pipe_getopt(void *arg, const char *name, void *buf, size_t *szp, nni_type t)
+{
+ ws_pipe *p = arg;
+ int rv;
+
+ if ((rv = nni_ws_getopt(p->ws, name, buf, szp, t)) == NNG_ENOTSUP) {
+ rv = nni_getopt(ws_pipe_options, name, p, buf, szp, t);
+ }
+ return (rv);
+}
+
static nni_tran_pipe_ops ws_pipe_ops = {
- .p_init = ws_pipe_init,
- .p_fini = ws_pipe_fini,
- .p_stop = ws_pipe_stop,
- .p_send = ws_pipe_send,
- .p_recv = ws_pipe_recv,
- .p_close = ws_pipe_close,
- .p_peer = ws_pipe_peer,
- .p_options = ws_pipe_options,
+ .p_init = ws_pipe_init,
+ .p_fini = ws_pipe_fini,
+ .p_stop = ws_pipe_stop,
+ .p_send = ws_pipe_send,
+ .p_recv = ws_pipe_recv,
+ .p_close = ws_pipe_close,
+ .p_peer = ws_pipe_peer,
+ .p_getopt = ws_pipe_getopt,
};
static nni_option ws_dialer_options[] = {