Commit 67a098c1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

gnutls: drop useless global mutex and init if version >= 3.3.0

(cherry picked from commit 6c12257639281c7631c2159d1efd3a052df09c34)

Conflicts:
	modules/misc/gnutls.c
parent 2be9caa6
...@@ -87,52 +87,64 @@ vlc_module_begin () ...@@ -87,52 +87,64 @@ vlc_module_begin ()
change_string_list (priorities_values, priorities_text) change_string_list (priorities_values, priorities_text)
vlc_module_end () vlc_module_end ()
#if (GNUTLS_VERSION_NUMBER >= 0x030300)
static int gnutls_Init (vlc_object_t *obj)
{
const char *version = gnutls_check_version ("3.3.0");
if (version == NULL)
{
msg_Err (obj, "unsupported GnuTLS version");
return -1;
}
msg_Dbg (p_this, "using GnuTLS verson %s", version);
return 0;
}
# define gnutls_Deinit() (void)0
#else
static vlc_mutex_t gnutls_mutex = VLC_STATIC_MUTEX; static vlc_mutex_t gnutls_mutex = VLC_STATIC_MUTEX;
/** /**
* Initializes GnuTLS with proper locking. * Initializes GnuTLS with proper locking.
* @return VLC_SUCCESS on success, a VLC error code otherwise. * @return VLC_SUCCESS on success, a VLC error code otherwise.
*/ */
static int gnutls_Init (vlc_object_t *p_this) static int gnutls_Init (vlc_object_t *obj)
{ {
int ret = VLC_EGENERIC; const char *version = gnutls_check_version ("3.0.20");
if (version == NULL)
vlc_mutex_lock (&gnutls_mutex);
if (gnutls_global_init ())
{ {
msg_Err (p_this, "cannot initialize GnuTLS"); msg_Err (obj, "unsupported GnuTLS version");
goto error; return -1;
} }
msg_Dbg (obj, "using GnuTLS verson %s", version);
const char *psz_version = gnutls_check_version ("3.0.20"); if (gnutls_check_version ("3.3.0") == NULL)
if (psz_version == NULL)
{ {
msg_Err (p_this, "unsupported GnuTLS version"); int val;
gnutls_global_deinit ();
goto error;
}
msg_Dbg (p_this, "GnuTLS v%s initialized", psz_version); vlc_mutex_lock (&gnutls_mutex);
ret = VLC_SUCCESS; val = gnutls_global_init ();
vlc_mutex_unlock (&gnutls_mutex);
error: if (val)
vlc_mutex_unlock (&gnutls_mutex); {
return ret; msg_Err (obj, "cannot initialize GnuTLS");
return -1;
}
}
return 0;
} }
/** /**
* Deinitializes GnuTLS. * Deinitializes GnuTLS.
*/ */
static void gnutls_Deinit (vlc_object_t *p_this) static void gnutls_Deinit (void)
{ {
vlc_mutex_lock (&gnutls_mutex); vlc_mutex_lock (&gnutls_mutex);
gnutls_global_deinit (); gnutls_global_deinit ();
msg_Dbg (p_this, "GnuTLS deinitialized");
vlc_mutex_unlock (&gnutls_mutex); vlc_mutex_unlock (&gnutls_mutex);
} }
#endif
static int gnutls_Error (vlc_object_t *obj, int val) static int gnutls_Error (vlc_object_t *obj, int val)
{ {
...@@ -724,7 +736,7 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key) ...@@ -724,7 +736,7 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
error: error:
free (sys); free (sys);
gnutls_Deinit (VLC_OBJECT(crd)); gnutls_Deinit ();
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -739,8 +751,7 @@ static void CloseServer (vlc_tls_creds_t *crd) ...@@ -739,8 +751,7 @@ static void CloseServer (vlc_tls_creds_t *crd)
gnutls_certificate_free_credentials (sys->x509_cred); gnutls_certificate_free_credentials (sys->x509_cred);
gnutls_dh_params_deinit (sys->dh_params); gnutls_dh_params_deinit (sys->dh_params);
free (sys); free (sys);
gnutls_Deinit ();
gnutls_Deinit (VLC_OBJECT(crd));
} }
/** /**
...@@ -783,7 +794,7 @@ static int OpenClient (vlc_tls_creds_t *crd) ...@@ -783,7 +794,7 @@ static int OpenClient (vlc_tls_creds_t *crd)
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
free (sys); free (sys);
gnutls_Deinit (VLC_OBJECT(crd)); gnutls_Deinit ();
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -793,6 +804,5 @@ static void CloseClient (vlc_tls_creds_t *crd) ...@@ -793,6 +804,5 @@ static void CloseClient (vlc_tls_creds_t *crd)
gnutls_certificate_free_credentials (sys->x509_cred); gnutls_certificate_free_credentials (sys->x509_cred);
free (sys); free (sys);
gnutls_Deinit ();
gnutls_Deinit (VLC_OBJECT(crd));
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment