[vlc-commits] tls: use const callbacks struct for client
Rémi Denis-Courmont
git at videolan.org
Sun Nov 18 16:57:30 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 18 15:12:16 2018 +0200| [bae5f8438f55ec8008ad395e3c3352e2cc430cbd] | committer: Rémi Denis-Courmont
tls: use const callbacks struct for client
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bae5f8438f55ec8008ad395e3c3352e2cc430cbd
---
include/vlc_tls.h | 7 +++++--
modules/misc/gnutls.c | 12 ++++++++----
modules/misc/securetransport.c | 12 ++++++++----
src/network/tls.c | 6 +++---
4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index 7e4e179c8c..957a9aa87c 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -139,16 +139,19 @@ struct vlc_tls_operations
typedef struct vlc_tls_client
{
struct vlc_common_members obj;
-
+ const struct vlc_tls_client_operations *ops;
void *sys;
+} vlc_tls_client_t;
+struct vlc_tls_client_operations
+{
vlc_tls_t *(*open)(struct vlc_tls_client *, vlc_tls_t *sock,
const char *host, const char *const *alpn);
int (*handshake)(vlc_tls_t *session,
const char *hostname, const char *service,
char ** /*restrict*/ alp);
void (*destroy)(struct vlc_tls_client *);
-} vlc_tls_client_t;
+};
/**
* Allocates TLS client-side credentials.
diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index 23654bab1a..d51e223c9a 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -549,6 +549,13 @@ static void gnutls_ClientDestroy(vlc_tls_client_t *crd)
gnutls_certificate_free_credentials(x509);
}
+static const struct vlc_tls_client_operations gnutls_ClientOps =
+{
+ .open = gnutls_ClientSessionOpen,
+ .handshake = gnutls_ClientHandshake,
+ .destroy = gnutls_ClientDestroy,
+};
+
/**
* Initializes a client-side TLS credentials.
*/
@@ -592,11 +599,8 @@ static int OpenClient(vlc_tls_client_t *crd)
gnutls_certificate_set_verify_flags (x509,
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
+ crd->ops = &gnutls_ClientOps;
crd->sys = x509;
- crd->open = gnutls_ClientSessionOpen;
- crd->handshake = gnutls_ClientHandshake;
- crd->destroy = gnutls_ClientDestroy;
-
return VLC_SUCCESS;
}
diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index 1cae2e79f2..fdf5adbabf 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -818,6 +818,13 @@ static void st_ClientDestroy (vlc_tls_client_t *crd) {
free(sys);
}
+static const struct vlc_tls_client_operations st_ClientOps =
+{
+ .open = st_ClientSessionOpen,
+ .handshake = st_Handshake,
+ .destroy = st_ClientDestroy,
+};
+
/**
* Initializes a client-side TLS credentials.
*/
@@ -832,11 +839,8 @@ static int OpenClient (vlc_tls_client_t *crd) {
sys->whitelist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
sys->server_cert_chain = NULL;
+ crd->ops = &st_ClientOps;
crd->sys = sys;
- crd->open = st_ClientSessionOpen;
- crd->handshake = st_Handshake;
- crd->destroy = st_ClientDestroy;
-
return VLC_SUCCESS;
}
diff --git a/src/network/tls.c b/src/network/tls.c
index b7887add1e..3de44cedff 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -121,7 +121,7 @@ void vlc_tls_ClientDelete(vlc_tls_client_t *crd)
if (crd == NULL)
return;
- crd->destroy(crd);
+ crd->ops->destroy(crd);
vlc_objres_clear(VLC_OBJECT(crd));
vlc_object_release (crd);
}
@@ -149,7 +149,7 @@ vlc_tls_t *vlc_tls_ClientSessionCreate(vlc_tls_client_t *crd, vlc_tls_t *sock,
{
int val;
int canc = vlc_savecancel();
- vlc_tls_t *session = crd->open(crd, sock, host, alpn);
+ vlc_tls_t *session = crd->ops->open(crd, sock, host, alpn);
vlc_restorecancel(canc);
if (session == NULL)
@@ -162,7 +162,7 @@ vlc_tls_t *vlc_tls_ClientSessionCreate(vlc_tls_client_t *crd, vlc_tls_t *sock,
deadline += VLC_TICK_FROM_MS( var_InheritInteger (crd, "ipv4-timeout") );
vlc_cleanup_push (cleanup_tls, session);
- while ((val = crd->handshake(session, host, service, alp)) != 0)
+ while ((val = crd->ops->handshake(session, host, service, alp)) != 0)
{
struct pollfd ufd[1];
More information about the vlc-commits
mailing list