[vlc-commits] tls: use const callbacks struct for server
Rémi Denis-Courmont
git at videolan.org
Sun Nov 18 16:57:29 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 18 15:12:16 2018 +0200| [26f58486cb511327354ab08d5b9030273b7a71b3] | committer: Rémi Denis-Courmont
tls: use const callbacks struct for server
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=26f58486cb511327354ab08d5b9030273b7a71b3
---
include/vlc_tls.h | 10 +++++++---
modules/misc/gnutls.c | 12 ++++++++----
modules/misc/securetransport.c | 11 ++++++++---
src/network/tls.c | 4 ++--
4 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index 48e4a77f25..7e4e179c8c 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -214,14 +214,18 @@ VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate(vlc_tls_client_t *creds,
typedef struct vlc_tls_server
{
struct vlc_common_members obj;
-
+ const struct vlc_tls_server_operations *ops;
void *sys;
+} vlc_tls_server_t;
+
+struct vlc_tls_server_operations
+{
vlc_tls_t *(*open)(struct vlc_tls_server *, vlc_tls_t *sock,
const char *const *alpn);
int (*handshake)(vlc_tls_t *session, char ** /*restrict*/ alp);
void (*destroy)(struct vlc_tls_server *);
-} vlc_tls_server_t;
+};
/**
* Allocates server TLS credentials.
@@ -239,7 +243,7 @@ VLC_API vlc_tls_server_t *vlc_tls_ServerCreate(vlc_object_t *,
static inline int vlc_tls_SessionHandshake(vlc_tls_server_t *crd,
vlc_tls_t *tls)
{
- return crd->handshake(tls, NULL);
+ return crd->ops->handshake(tls, NULL);
}
/**
diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index 512db14233..23654bab1a 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -640,6 +640,13 @@ static void gnutls_ServerDestroy(vlc_tls_server_t *crd)
free(sys);
}
+static const struct vlc_tls_server_operations gnutls_ServerOps =
+{
+ .open = gnutls_ServerSessionOpen,
+ .handshake = gnutls_ServerHandshake,
+ .destroy = gnutls_ServerDestroy,
+};
+
/**
* Allocates a whole server's TLS credentials.
*/
@@ -720,11 +727,8 @@ static int OpenServer(vlc_tls_server_t *crd, const char *cert, const char *key)
msg_Dbg (crd, "ciphers parameters loaded");
+ crd->ops = &gnutls_ServerOps;
crd->sys = sys;
- crd->open = gnutls_ServerSessionOpen;
- crd->handshake = gnutls_ServerHandshake;
- crd->destroy = gnutls_ServerDestroy;
-
return VLC_SUCCESS;
error:
diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index 76d1f10772..1cae2e79f2 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -890,6 +890,13 @@ static void st_ServerDestroy (vlc_tls_server_t *crd) {
free(sys);
}
+static const struct vlc_tls_server_operations st_ServerOps =
+{
+ .open = st_ServerSessionOpen,
+ .handshake = st_ServerHandshake,
+ .destroy = st_ServerDestroy,
+};
+
/**
* Initializes server-side TLS credentials.
*/
@@ -994,10 +1001,8 @@ static int OpenServer (vlc_tls_server_t *crd, const char *cert, const char *key)
sys->server_cert_chain = server_cert_chain;
sys->whitelist = NULL;
+ crd->ops = &st_ServerOps;
crd->sys = sys;
- crd->open = st_ServerSessionOpen;
- crd->handshake = st_ServerHandshake;
- crd->destroy = st_ServerDestroy;
out:
if (policy)
diff --git a/src/network/tls.c b/src/network/tls.c
index fb7bb6e0c7..b7887add1e 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -93,7 +93,7 @@ void vlc_tls_ServerDelete(vlc_tls_server_t *crd)
if (crd == NULL)
return;
- crd->destroy(crd);
+ crd->ops->destroy(crd);
vlc_objres_clear(VLC_OBJECT(crd));
vlc_object_release(crd);
}
@@ -204,7 +204,7 @@ vlc_tls_t *vlc_tls_ServerSessionCreate(vlc_tls_server_t *crd,
const char *const *alpn)
{
int canc = vlc_savecancel();
- vlc_tls_t *session = crd->open(crd, sock, alpn);
+ vlc_tls_t *session = crd->ops->open(crd, sock, alpn);
vlc_restorecancel(canc);
if (session != NULL)
session->p = sock;
More information about the vlc-commits
mailing list