Make stream_upgrade_to_tls a virtual method

websocket-tls
Andri Yngvason 2023-04-30 16:37:30 +00:00
parent 34578aa5a4
commit 08f01afee4
4 changed files with 13 additions and 1 deletions

View File

@ -70,6 +70,7 @@ struct stream_impl {
stream_req_fn on_done, void* userdata);
int (*send_first)(struct stream*, struct rcbuf* payload);
void (*exec_and_send)(struct stream*, stream_exec_fn, void* userdata);
int (*upgrade_to_tls)(struct stream*, void* context);
};
// TODO: Move some of these struct members into their respective implementation
@ -114,5 +115,6 @@ int stream_send_first(struct stream* self, struct rcbuf* payload);
void stream_exec_and_send(struct stream* self, stream_exec_fn, void* userdata);
#ifdef ENABLE_TLS
int stream_upgrade_tcp_to_tls(struct stream* self, void* context);
int stream_upgrade_to_tls(struct stream* self, void* context);
#endif

View File

@ -33,6 +33,7 @@
#include "stream.h"
#include "stream-common.h"
#include "sys/queue.h"
#include "neatvnc.h"
static int stream__try_tls_accept(struct stream* self);
@ -241,10 +242,12 @@ static struct stream_impl impl = {
.send = stream_gnutls_send,
};
int stream_upgrade_to_tls(struct stream* self, void* context)
int stream_upgrade_tcp_to_tls(struct stream* self, void* context)
{
int rc;
nvnc_log(NVNC_LOG_DEBUG, "Uprading stream %p to TLS", self);
rc = gnutls_init(&self->tls_session, GNUTLS_SERVER | GNUTLS_NONBLOCK);
if (rc != GNUTLS_E_SUCCESS)
return -1;

View File

@ -251,6 +251,7 @@ static struct stream_impl impl = {
.send = stream_tcp_send,
.send_first = stream_tcp_send_first,
.exec_and_send = stream_tcp_exec_and_send,
.upgrade_to_tls = stream_upgrade_tcp_to_tls,
};
struct stream* stream_new(int fd, stream_event_fn on_event, void* userdata)

View File

@ -65,3 +65,9 @@ void stream_exec_and_send(struct stream* self, stream_exec_fn exec_fn,
else
stream_send(self, exec_fn(self, userdata), NULL, NULL);
}
int stream_upgrade_to_tls(struct stream* self, void* context)
{
assert(self->impl && self->impl->upgrade_to_tls);
return self->impl->upgrade_to_tls(self, context);
}