aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental
diff options
context:
space:
mode:
Diffstat (limited to 'src/supplemental')
-rw-r--r--src/supplemental/http/http_api.h15
-rw-r--r--src/supplemental/http/http_conn.c134
-rw-r--r--src/supplemental/tcp/tcp.c45
-rw-r--r--src/supplemental/tls/mbedtls/tls.c66
-rw-r--r--src/supplemental/tls/none/tls.c42
-rw-r--r--src/supplemental/tls/tls_api.h20
-rw-r--r--src/supplemental/websocket/websocket.c55
-rw-r--r--src/supplemental/websocket/websocket.h23
8 files changed, 197 insertions, 203 deletions
diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h
index a13348be..569e8532 100644
--- a/src/supplemental/http/http_api.h
+++ b/src/supplemental/http/http_api.h
@@ -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
@@ -12,9 +13,8 @@
#define NNG_SUPPLEMENTAL_HTTP_HTTP_API_H
#include "core/nng_impl.h"
-#include "nng/supplemental/tls/tls.h"
-
-#include "nng/supplemental/http/http.h"
+#include <nng/supplemental/http/http.h>
+#include <nng/supplemental/tls/tls.h>
// This represents the "internal" HTTP API. It should not be used
// or exposed to applications directly.
@@ -102,6 +102,10 @@ extern int nni_http_conn_init_tls(
extern void nni_http_conn_close(nni_http_conn *);
extern void nni_http_conn_fini(nni_http_conn *);
+extern int nni_http_conn_getopt(
+ nni_http_conn *, const char *, void *, size_t *, nni_type);
+extern int nni_http_conn_setopt(
+ nni_http_conn *, const char *, const void *, size_t, nni_type);
// Reading messages -- the caller must supply a preinitialized (but otherwise
// idle) message. We recommend the caller store this in the aio's user data.
@@ -161,11 +165,6 @@ extern void nni_http_read(nni_http_conn *, nni_aio *);
extern void nni_http_read_full(nni_http_conn *, nni_aio *);
extern void nni_http_write(nni_http_conn *, nni_aio *);
extern void nni_http_write_full(nni_http_conn *, nni_aio *);
-extern int nni_http_sock_addr(nni_http_conn *, nni_sockaddr *);
-extern int nni_http_peer_addr(nni_http_conn *, nni_sockaddr *);
-
-// nni_http_tls_verified returns true if the peer has been verified using TLS.
-extern bool nni_http_tls_verified(nni_http_conn *);
// nni_http_server will look for an existing server with the same
// name and port, or create one if one does not exist. The servers
diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c
index 4d57281f..7c6159cd 100644
--- a/src/supplemental/http/http_conn.c
+++ b/src/supplemental/http/http_conn.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
@@ -13,11 +14,12 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "nng/supplemental/tls/tls.h"
#include "supplemental/tls/tls_api.h"
#include "http_api.h"
+#include <nng/supplemental/tls/tls.h>
+
// We insist that individual headers fit in 8K.
// If you need more than that, you need something we can't do.
#define HTTP_BUFSIZE 8192
@@ -42,18 +44,20 @@ typedef void (*http_read_fn)(void *, nni_aio *);
typedef void (*http_write_fn)(void *, nni_aio *);
typedef void (*http_close_fn)(void *);
typedef void (*http_fini_fn)(void *);
-typedef bool (*http_verified_fn)(void *);
typedef int (*http_addr_fn)(void *, nni_sockaddr *);
-
-typedef struct nni_http_tran {
- http_read_fn h_read;
- http_write_fn h_write;
- http_addr_fn h_sock_addr;
- http_addr_fn h_peer_addr;
- http_verified_fn h_verified;
- http_close_fn h_close;
- http_fini_fn h_fini;
-} nni_http_tran;
+typedef int (*http_getopt_fn)(
+ void *, const char *, void *, size_t *, nni_type);
+typedef int (*http_setopt_fn)(
+ void *, const char *, const void *, size_t, nni_type);
+
+typedef struct {
+ http_read_fn h_read;
+ http_write_fn h_write;
+ http_getopt_fn h_getopt;
+ http_setopt_fn h_setopt;
+ http_close_fn h_close;
+ http_fini_fn h_fini;
+} http_tran;
#define SET_RD_FLAVOR(aio, f) \
nni_aio_set_prov_extra(aio, 0, ((void *) (intptr_t)(f)))
@@ -63,18 +67,17 @@ typedef struct nni_http_tran {
#define GET_WR_FLAVOR(aio) (int) ((intptr_t) nni_aio_get_prov_extra(aio, 0))
struct nng_http_conn {
- void * sock;
- http_read_fn rd;
- http_write_fn wr;
- http_addr_fn sock_addr;
- http_addr_fn peer_addr;
- http_verified_fn verified;
- http_close_fn close;
- http_fini_fn fini;
- void * ctx;
- bool closed;
- nni_list rdq; // high level http read requests
- nni_list wrq; // high level http write requests
+ void * sock;
+ http_read_fn rd;
+ http_write_fn wr;
+ http_setopt_fn setopt;
+ http_getopt_fn getopt;
+ http_close_fn close;
+ http_fini_fn fini;
+ void * ctx;
+ bool closed;
+ nni_list rdq; // high level http read requests
+ nni_list wrq; // high level http write requests
nni_aio *rd_uaio; // user aio for read
nni_aio *wr_uaio; // user aio for write
@@ -669,32 +672,31 @@ nni_http_write_full(nni_http_conn *conn, nni_aio *aio)
}
int
-nni_http_sock_addr(nni_http_conn *conn, nni_sockaddr *sa)
+nni_http_conn_getopt(
+ nni_http_conn *conn, const char *name, void *buf, size_t *szp, nni_type t)
{
int rv;
nni_mtx_lock(&conn->mtx);
- rv = conn->closed ? NNG_ECLOSED : conn->sock_addr(conn->sock, sa);
+ if (conn->closed) {
+ rv = NNG_ECLOSED;
+ } else {
+ rv = conn->getopt(conn->sock, name, buf, szp, t);
+ }
nni_mtx_unlock(&conn->mtx);
return (rv);
}
int
-nni_http_peer_addr(nni_http_conn *conn, nni_sockaddr *sa)
+nni_http_conn_setopt(nni_http_conn *conn, const char *name, const void *buf,
+ size_t sz, nni_type t)
{
int rv;
nni_mtx_lock(&conn->mtx);
- rv = conn->closed ? NNG_ECLOSED : conn->peer_addr(conn->sock, sa);
- nni_mtx_unlock(&conn->mtx);
- return (rv);
-}
-
-bool
-nni_http_tls_verified(nni_http_conn *conn)
-{
- bool rv;
-
- nni_mtx_lock(&conn->mtx);
- rv = conn->closed ? false : conn->verified(conn->sock);
+ if (conn->closed) {
+ rv = NNG_ECLOSED;
+ } else {
+ rv = conn->setopt(conn->sock, name, buf, sz, t);
+ }
nni_mtx_unlock(&conn->mtx);
return (rv);
}
@@ -721,7 +723,7 @@ nni_http_conn_fini(nni_http_conn *conn)
}
static int
-http_init(nni_http_conn **connp, nni_http_tran *tran, void *data)
+http_init(nni_http_conn **connp, http_tran *tran, void *data)
{
nni_http_conn *conn;
int rv;
@@ -745,35 +747,26 @@ http_init(nni_http_conn **connp, nni_http_tran *tran, void *data)
return (rv);
}
- conn->sock = data;
- conn->rd = tran->h_read;
- conn->wr = tran->h_write;
- conn->close = tran->h_close;
- conn->fini = tran->h_fini;
- conn->sock_addr = tran->h_sock_addr;
- conn->peer_addr = tran->h_peer_addr;
- conn->verified = tran->h_verified;
+ conn->sock = data;
+ conn->rd = tran->h_read;
+ conn->wr = tran->h_write;
+ conn->close = tran->h_close;
+ conn->fini = tran->h_fini;
+ conn->getopt = tran->h_getopt;
+ conn->setopt = tran->h_setopt;
*connp = conn;
return (0);
}
-static bool
-nni_http_verified_tcp(void *arg)
-{
- NNI_ARG_UNUSED(arg);
- return (false);
-}
-
-static nni_http_tran http_tcp_ops = {
- .h_read = (http_read_fn) nni_tcp_conn_recv,
- .h_write = (http_write_fn) nni_tcp_conn_send,
- .h_close = (http_close_fn) nni_tcp_conn_close,
- .h_fini = (http_fini_fn) nni_tcp_conn_fini,
- .h_sock_addr = (http_addr_fn) nni_tcp_conn_sockname,
- .h_peer_addr = (http_addr_fn) nni_tcp_conn_peername,
- .h_verified = (http_verified_fn) nni_http_verified_tcp,
+static http_tran http_tcp_ops = {
+ .h_read = (http_read_fn) nni_tcp_conn_recv,
+ .h_write = (http_write_fn) nni_tcp_conn_send,
+ .h_close = (http_close_fn) nni_tcp_conn_close,
+ .h_fini = (http_fini_fn) nni_tcp_conn_fini,
+ .h_getopt = (http_getopt_fn) nni_tcp_conn_getopt,
+ .h_setopt = (http_setopt_fn) nni_tcp_conn_setopt,
};
int
@@ -787,14 +780,13 @@ nni_http_conn_init_tcp(nni_http_conn **connp, nni_tcp_conn *tcp)
}
#ifdef NNG_SUPP_TLS
-static nni_http_tran http_tls_ops = {
- .h_read = (http_read_fn) nni_tls_recv,
- .h_write = (http_write_fn) nni_tls_send,
- .h_close = (http_close_fn) nni_tls_close,
- .h_fini = (http_fini_fn) nni_tls_fini,
- .h_sock_addr = (http_addr_fn) nni_tls_sockname,
- .h_peer_addr = (http_addr_fn) nni_tls_peername,
- .h_verified = (http_verified_fn) nni_tls_verified,
+static http_tran http_tls_ops = {
+ .h_read = (http_read_fn) nni_tls_recv,
+ .h_write = (http_write_fn) nni_tls_send,
+ .h_close = (http_close_fn) nni_tls_close,
+ .h_fini = (http_fini_fn) nni_tls_fini,
+ .h_getopt = (http_getopt_fn) nni_tls_getopt,
+ .h_setopt = (http_setopt_fn) nni_tls_setopt,
};
int
diff --git a/src/supplemental/tcp/tcp.c b/src/supplemental/tcp/tcp.c
index 2cb80d96..f880362b 100644
--- a/src/supplemental/tcp/tcp.c
+++ b/src/supplemental/tcp/tcp.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
@@ -51,27 +52,17 @@ nng_tcp_recv(nng_tcp *tcp, nng_aio *aio)
}
int
-nng_tcp_sockname(nng_tcp *tcp, nng_sockaddr *sa)
+nng_tcp_getopt(nng_tcp *tcp, const char *name, void *buf, size_t *szp)
{
- return (nni_tcp_conn_sockname((void *) tcp, sa));
+ return (nni_tcp_conn_getopt(
+ (void *) tcp, name, buf, szp, NNI_TYPE_OPAQUE));
}
int
-nng_tcp_peername(nng_tcp *tcp, nng_sockaddr *sa)
+nng_tcp_setopt(nng_tcp *tcp, const char *name, const void *buf, size_t sz)
{
- return (nni_tcp_conn_peername((void *) tcp, sa));
-}
-
-int
-nng_tcp_set_nodelay(nng_tcp *tcp, bool nodelay)
-{
- return (nni_tcp_conn_set_nodelay((void *) tcp, nodelay));
-}
-
-int
-nng_tcp_set_keepalive(nng_tcp *tcp, bool ka)
-{
- return (nni_tcp_conn_set_keepalive((void *) tcp, ka));
+ return (
+ nni_tcp_conn_setopt((void *) tcp, name, buf, sz, NNI_TYPE_OPAQUE));
}
int
@@ -101,12 +92,6 @@ nng_tcp_dialer_free(nng_tcp_dialer *d)
nni_tcp_dialer_fini((void *) d);
}
-int
-nng_tcp_dialer_set_source(nng_tcp_dialer *d, const nng_sockaddr *sa)
-{
- return (nni_tcp_dialer_set_src_addr((void *) d, sa));
-}
-
void
nng_tcp_dialer_dial(nng_tcp_dialer *d, const nng_sockaddr *sa, nng_aio *aio)
{
@@ -151,3 +136,19 @@ nng_tcp_listener_accept(nng_tcp_listener *l, nng_aio *aio)
{
nni_tcp_listener_accept((void *) l, aio);
}
+
+int
+nng_tcp_listener_getopt(
+ nng_tcp_listener *l, const char *name, void *buf, size_t *szp)
+{
+ return (nni_tcp_listener_getopt(
+ (void *) l, name, buf, szp, NNI_TYPE_OPAQUE));
+}
+
+int
+nng_tcp_listener_setopt(
+ nng_tcp_listener *l, const char *name, const void *buf, size_t sz)
+{
+ return (nni_tcp_listener_setopt(
+ (void *) l, name, buf, sz, NNI_TYPE_OPAQUE));
+} \ No newline at end of file
diff --git a/src/supplemental/tls/mbedtls/tls.c b/src/supplemental/tls/mbedtls/tls.c
index c01ff2ed..29f1873e 100644
--- a/src/supplemental/tls/mbedtls/tls.c
+++ b/src/supplemental/tls/mbedtls/tls.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
@@ -27,10 +28,10 @@
#include "mbedtls/ssl.h"
#include "core/nng_impl.h"
-
-#include "nng/supplemental/tls/tls.h"
#include "supplemental/tls/tls_api.h"
+#include <nng/supplemental/tls/tls.h>
+
// Implementation note. This implementation buffers data between the TLS
// encryption layer (mbedTLS) and the underlying TCP socket. As a result,
// there may be some additional latency caused by buffer draining and
@@ -310,11 +311,13 @@ nni_tls_init(nni_tls **tpp, nng_tls_config *cfg, nni_tcp_conn *tcp)
{
nni_tls *tp;
int rv;
+ bool on = true;
// During the handshake, disable Nagle to shorten the
// negotiation. Once things are set up the caller can
// re-enable Nagle if so desired.
- (void) nni_tcp_conn_set_nodelay(tcp, true);
+ (void) nni_tcp_conn_setopt(
+ tcp, NNG_OPT_TCP_NODELAY, &on, sizeof(on), NNI_TYPE_BOOL);
if ((tp = NNI_ALLOC_STRUCT(tp)) == NULL) {
return (NNG_ENOMEM);
@@ -612,28 +615,49 @@ nni_tls_recv(nni_tls *tp, nni_aio *aio)
nni_mtx_unlock(&tp->lk);
}
-int
-nni_tls_peername(nni_tls *tp, nni_sockaddr *sa)
+static int
+tls_get_verified(void *arg, void *buf, size_t *szp, nni_type t)
{
- return (nni_tcp_conn_peername(tp->tcp, sa));
-}
+ nni_tls *tp = arg;
+ bool v = (mbedtls_ssl_get_verify_result(&tp->ctx) == 0);
-int
-nni_tls_sockname(nni_tls *tp, nni_sockaddr *sa)
-{
- return (nni_tcp_conn_sockname(tp->tcp, sa));
+ return (nni_copyout_bool(v, buf, szp, t));
}
+static const nni_option tls_options[] = {
+ {
+ .o_name = NNG_OPT_TLS_VERIFIED,
+ .o_get = tls_get_verified,
+ },
+ {
+ .o_name = NULL,
+ },
+};
+
int
-nni_tls_set_nodelay(nni_tls *tp, bool val)
+nni_tls_setopt(
+ nni_tls *tp, const char *name, const void *buf, size_t sz, nni_type t)
{
- return (nni_tcp_conn_set_nodelay(tp->tcp, val));
+ int rv;
+
+ if ((rv = nni_tcp_conn_setopt(tp->tcp, name, buf, sz, t)) !=
+ NNG_ENOTSUP) {
+ return (rv);
+ }
+ return (nni_setopt(tls_options, name, tp, buf, sz, t));
}
int
-nni_tls_set_keepalive(nni_tls *tp, bool val)
+nni_tls_getopt(
+ nni_tls *tp, const char *name, void *buf, size_t *szp, nni_type t)
{
- return (nni_tcp_conn_set_keepalive(tp->tcp, val));
+ int rv;
+
+ if ((rv = nni_tcp_conn_getopt(tp->tcp, name, buf, szp, t)) !=
+ NNG_ENOTSUP) {
+ return (rv);
+ }
+ return (nni_getopt(tls_options, name, tp, buf, szp, t));
}
static void
@@ -790,18 +814,6 @@ nni_tls_close(nni_tls *tp)
nni_mtx_unlock(&tp->lk);
}
-const char *
-nni_tls_ciphersuite_name(nni_tls *tp)
-{
- return (mbedtls_ssl_get_ciphersuite(&tp->ctx));
-}
-
-bool
-nni_tls_verified(nni_tls *tp)
-{
- return (mbedtls_ssl_get_verify_result(&tp->ctx) == 0);
-}
-
int
nng_tls_config_server_name(nng_tls_config *cfg, const char *name)
{
diff --git a/src/supplemental/tls/none/tls.c b/src/supplemental/tls/none/tls.c
index e9d84e19..257bb6b1 100644
--- a/src/supplemental/tls/none/tls.c
+++ b/src/supplemental/tls/none/tls.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
@@ -17,9 +18,10 @@
// We provide stub functions only to satisfy linkage.
#include "core/nng_impl.h"
-#include "nng/supplemental/tls/tls.h"
#include "supplemental/tls/tls_api.h"
+#include <nng/supplemental/tls/tls.h>
+
void
nni_tls_config_fini(nng_tls_config *cfg)
{
@@ -72,40 +74,34 @@ nni_tls_recv(nni_tls *tp, nni_aio *aio)
nni_aio_finish_error(aio, NNG_ENOTSUP);
}
-int
-nni_tls_peername(nni_tls *tp, nni_sockaddr *sa)
-{
- NNI_ARG_UNUSED(tp);
- NNI_ARG_UNUSED(sa);
- return (NNG_ENOTSUP);
-}
-
-int
-nni_tls_sockname(nni_tls *tp, nni_sockaddr *sa)
-{
- NNI_ARG_UNUSED(tp);
- NNI_ARG_UNUSED(sa);
- return (NNG_ENOTSUP);
-}
-
void
nni_tls_close(nni_tls *tp)
{
NNI_ARG_UNUSED(tp);
}
-const char *
-nni_tls_ciphersuite_name(nni_tls *tp)
+int
+nni_tls_getopt(
+ nni_tls *tp, const char *name, void *buf, size_t *szp, nni_type t)
{
NNI_ARG_UNUSED(tp);
- return (NULL);
+ NNI_ARG_UNUSED(name);
+ NNI_ARG_UNUSED(buf);
+ NNI_ARG_UNUSED(szp);
+ NNI_ARG_UNUSED(t);
+ return (NNG_ENOTSUP);
}
-bool
-nni_tls_verified(nni_tls *tp)
+int
+nni_tls_setopt(
+ nni_tls *tp, const char *name, const void *buf, size_t sz, nni_type t)
{
NNI_ARG_UNUSED(tp);
- return (false);
+ NNI_ARG_UNUSED(name);
+ NNI_ARG_UNUSED(buf);
+ NNI_ARG_UNUSED(sz);
+ NNI_ARG_UNUSED(t);
+ return (NNG_ENOTSUP);
}
int
diff --git a/src/supplemental/tls/tls_api.h b/src/supplemental/tls/tls_api.h
index 53dba7fe..63424d5e 100644
--- a/src/supplemental/tls/tls_api.h
+++ b/src/supplemental/tls/tls_api.h
@@ -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
@@ -13,6 +14,8 @@
#include <stdbool.h>
+#include <nng/supplemental/tls/tls.h>
+
// nni_tls represents the context for a single TLS stream.
typedef struct nni_tls nni_tls;
@@ -36,19 +39,10 @@ extern void nni_tls_close(nni_tls *);
extern void nni_tls_fini(nni_tls *);
extern void nni_tls_send(nni_tls *, nng_aio *);
extern void nni_tls_recv(nni_tls *, nng_aio *);
-extern int nni_tls_sockname(nni_tls *, nni_sockaddr *);
-extern int nni_tls_peername(nni_tls *, nni_sockaddr *);
-extern int nni_tls_set_nodelay(nni_tls *, bool);
-extern int nni_tls_set_keepalive(nni_tls *, bool);
-
-// nni_tls_verified returns true if the peer, or false if the peer did not
-// verify. (During the handshake phase, the peer is not verified, so this
-// might return false if executed too soon. The verification status will
-// be accurate once the handshake is finished, however.
-extern bool nni_tls_verified(nni_tls *);
-
-// nni_tls_ciphersuite_name returns the name of the ciphersuite in use.
-extern const char *nni_tls_ciphersuite_name(nni_tls *);
+
+extern int nni_tls_setopt(
+ nni_tls *, const char *, const void *, size_t, nni_type);
+extern int nni_tls_getopt(nni_tls *, const char *, void *, size_t *, nni_type);
// TBD: getting additional peer certificate information...
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index c214e6d7..3d3a68cb 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/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
@@ -698,22 +699,45 @@ ws_send_control(nni_ws *ws, uint8_t op, uint8_t *buf, size_t len)
ws_start_write(ws);
}
+static const nni_option ws_options[] = {
+ {
+ .o_name = NULL,
+ },
+};
+
int
-nni_ws_sock_addr(nni_ws *ws, nni_sockaddr *sa)
+nni_ws_getopt(nni_ws *ws, const char *name, void *buf, size_t *szp, nni_type t)
{
int rv;
+
nni_mtx_lock(&ws->mtx);
- rv = ws->closed ? NNG_ECLOSED : nni_http_sock_addr(ws->http, sa);
+ if (ws->closed) {
+ nni_mtx_unlock(&ws->mtx);
+ return (NNG_ECLOSED);
+ }
+ rv = nni_http_conn_getopt(ws->http, name, buf, szp, t);
+ if (rv == NNG_ENOTSUP) {
+ rv = nni_getopt(ws_options, name, ws, buf, szp, t);
+ }
nni_mtx_unlock(&ws->mtx);
return (rv);
}
int
-nni_ws_peer_addr(nni_ws *ws, nni_sockaddr *sa)
+nni_ws_setopt(
+ nni_ws *ws, const char *name, const void *buf, size_t sz, nni_type t)
{
int rv;
+
nni_mtx_lock(&ws->mtx);
- rv = ws->closed ? NNG_ECLOSED : nni_http_peer_addr(ws->http, sa);
+ if (ws->closed) {
+ nni_mtx_unlock(&ws->mtx);
+ return (NNG_ECLOSED);
+ }
+ rv = nni_http_conn_setopt(ws->http, name, buf, sz, t);
+ if (rv == NNG_ENOTSUP) {
+ rv = nni_setopt(ws_options, name, ws, buf, sz, t);
+ }
nni_mtx_unlock(&ws->mtx);
return (rv);
}
@@ -1098,18 +1122,6 @@ nni_ws_close(nni_ws *ws)
nni_ws_close_error(ws, WS_CLOSE_NORMAL_CLOSE);
}
-nni_http_res *
-nni_ws_response(nni_ws *ws)
-{
- return (ws->res);
-}
-
-nni_http_req *
-nni_ws_request(nni_ws *ws)
-{
- return (ws->req);
-}
-
const char *
nni_ws_request_headers(nni_ws *ws)
{
@@ -1132,17 +1144,6 @@ nni_ws_response_headers(nni_ws *ws)
return (ws->reshdrs);
}
-bool
-nni_ws_tls_verified(nni_ws *ws)
-{
- bool rv;
-
- nni_mtx_lock(&ws->mtx);
- rv = nni_http_tls_verified(ws->http);
- nni_mtx_unlock(&ws->mtx);
- return (rv);
-}
-
static void
ws_fini(void *arg)
{
diff --git a/src/supplemental/websocket/websocket.h b/src/supplemental/websocket/websocket.h
index 9936b10f..88b4bfb4 100644
--- a/src/supplemental/websocket/websocket.h
+++ b/src/supplemental/websocket/websocket.h
@@ -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
@@ -52,18 +53,16 @@ extern int nni_ws_dialer_get_tls(nni_ws_dialer *, nng_tls_config **);
// not confirm the server's response at the HTTP level. (It can still issue
// a websocket close).
-extern void nni_ws_send_msg(nni_ws *, nng_aio *);
-extern void nni_ws_recv_msg(nni_ws *, nng_aio *);
-extern nng_http_res *nni_ws_response(nni_ws *);
-extern nng_http_req *nni_ws_request(nni_ws *);
-extern int nni_ws_sock_addr(nni_ws *, nni_sockaddr *);
-extern int nni_ws_peer_addr(nni_ws *, nni_sockaddr *);
-extern void nni_ws_close(nni_ws *);
-extern void nni_ws_close_error(nni_ws *, uint16_t);
-extern void nni_ws_fini(nni_ws *);
-extern const char * nni_ws_response_headers(nni_ws *);
-extern const char * nni_ws_request_headers(nni_ws *);
-extern bool nni_ws_tls_verified(nni_ws *);
+extern void nni_ws_send_msg(nni_ws *, nng_aio *);
+extern void nni_ws_recv_msg(nni_ws *, nng_aio *);
+extern void nni_ws_close(nni_ws *);
+extern void nni_ws_close_error(nni_ws *, uint16_t);
+extern void nni_ws_fini(nni_ws *);
+extern const char *nni_ws_response_headers(nni_ws *);
+extern const char *nni_ws_request_headers(nni_ws *);
+extern int nni_ws_getopt(nni_ws *, const char *, void *, size_t *, nni_type);
+extern int nni_ws_setopt(
+ nni_ws *, const char *, const void *, size_t, nni_type);
// The implementation will send periodic PINGs, and respond with PONGs.