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

tls: remove virtual_socket_t and clean send/recv prototypes up

parent c2a21b27
...@@ -291,7 +291,6 @@ typedef struct filter_t filter_t; ...@@ -291,7 +291,6 @@ typedef struct filter_t filter_t;
typedef struct filter_sys_t filter_sys_t; typedef struct filter_sys_t filter_sys_t;
/* Network */ /* Network */
typedef struct virtual_socket_t v_socket_t;
typedef struct vlc_url_t vlc_url_t; typedef struct vlc_url_t vlc_url_t;
/* Misc */ /* Misc */
......
...@@ -132,14 +132,6 @@ int net_Subscribe (vlc_object_t *obj, int fd, const struct sockaddr *addr, ...@@ -132,14 +132,6 @@ int net_Subscribe (vlc_object_t *obj, int fd, const struct sockaddr *addr,
VLC_API int net_SetCSCov( int fd, int sendcov, int recvcov ); VLC_API int net_SetCSCov( int fd, int sendcov, int recvcov );
/* Functions to read from or write to the networking layer */
struct virtual_socket_t
{
void *p_sys;
int (*pf_recv) ( void *, void *, size_t );
int (*pf_send) ( void *, const void *, size_t );
};
VLC_API ssize_t net_Read( vlc_object_t *p_this, int fd, void *p_data, size_t i_data ); VLC_API ssize_t net_Read( vlc_object_t *p_this, int fd, void *p_data, size_t i_data );
#define net_Read(a,b,c,d) net_Read(VLC_OBJECT(a),b,c,d) #define net_Read(a,b,c,d) net_Read(VLC_OBJECT(a),b,c,d)
VLC_API ssize_t net_Write( vlc_object_t *p_this, int fd, const void *p_data, size_t i_data ); VLC_API ssize_t net_Write( vlc_object_t *p_this, int fd, const void *p_data, size_t i_data );
......
...@@ -43,7 +43,8 @@ struct vlc_tls ...@@ -43,7 +43,8 @@ struct vlc_tls
void *sys; void *sys;
int fd; int fd;
struct virtual_socket_t sock; ssize_t (*recv)(struct vlc_tls *, void *, size_t);
ssize_t (*send)(struct vlc_tls *, const void *, size_t);
}; };
/** /**
......
...@@ -54,7 +54,7 @@ ssize_t vlc_https_recv(vlc_tls_t *tls, void *buf, size_t len) ...@@ -54,7 +54,7 @@ ssize_t vlc_https_recv(vlc_tls_t *tls, void *buf, size_t len)
while (count < len) while (count < len)
{ {
int canc = vlc_savecancel(); int canc = vlc_savecancel();
ssize_t val = tls->sock.pf_recv(tls, (char *)buf + count, len - count); ssize_t val = tls->recv(tls, (char *)buf + count, len - count);
vlc_restorecancel(canc); vlc_restorecancel(canc);
...@@ -115,7 +115,7 @@ ssize_t vlc_https_send(vlc_tls_t *tls, const void *buf, size_t len) ...@@ -115,7 +115,7 @@ ssize_t vlc_https_send(vlc_tls_t *tls, const void *buf, size_t len)
while (count < len) while (count < len)
{ {
int canc = vlc_savecancel(); int canc = vlc_savecancel();
ssize_t val = tls->sock.pf_send(tls, (char *)buf + count, len - count); ssize_t val = tls->send(tls, (char *)buf + count, len - count);
vlc_restorecancel(canc); vlc_restorecancel(canc);
......
...@@ -163,14 +163,11 @@ static ssize_t vlc_gnutls_writev (gnutls_transport_ptr_t ptr, ...@@ -163,14 +163,11 @@ static ssize_t vlc_gnutls_writev (gnutls_transport_ptr_t ptr,
/** /**
* Sends data through a TLS session. * Sends data through a TLS session.
*/ */
static int gnutls_Send (void *opaque, const void *buf, size_t length) static ssize_t gnutls_Send (vlc_tls_t *tls, const void *buf, size_t length)
{ {
assert (opaque != NULL);
vlc_tls_t *tls = opaque;
gnutls_session_t session = tls->sys; gnutls_session_t session = tls->sys;
ssize_t val = gnutls_record_send (session, buf, length);
int val = gnutls_record_send (session, buf, length);
return (val < 0) ? gnutls_Error (tls, val) : val; return (val < 0) ? gnutls_Error (tls, val) : val;
} }
...@@ -178,14 +175,11 @@ static int gnutls_Send (void *opaque, const void *buf, size_t length) ...@@ -178,14 +175,11 @@ static int gnutls_Send (void *opaque, const void *buf, size_t length)
/** /**
* Receives data through a TLS session. * Receives data through a TLS session.
*/ */
static int gnutls_Recv (void *opaque, void *buf, size_t length) static ssize_t gnutls_Recv (vlc_tls_t *tls, void *buf, size_t length)
{ {
assert (opaque != NULL);
vlc_tls_t *tls = opaque;
gnutls_session_t session = tls->sys; gnutls_session_t session = tls->sys;
ssize_t val = gnutls_record_recv (session, buf, length);
int val = gnutls_record_recv (session, buf, length);
return (val < 0) ? gnutls_Error (tls, val) : val; return (val < 0) ? gnutls_Error (tls, val) : val;
} }
...@@ -255,9 +249,8 @@ static int gnutls_SessionOpen (vlc_tls_t *tls, int type, ...@@ -255,9 +249,8 @@ static int gnutls_SessionOpen (vlc_tls_t *tls, int type,
gnutls_transport_set_vec_push_function (session, vlc_gnutls_writev); gnutls_transport_set_vec_push_function (session, vlc_gnutls_writev);
#endif #endif
tls->sys = session; tls->sys = session;
tls->sock.p_sys = NULL; tls->send = gnutls_Send;
tls->sock.pf_send = gnutls_Send; tls->recv = gnutls_Recv;
tls->sock.pf_recv = gnutls_Recv;
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
...@@ -332,9 +325,7 @@ static void gnutls_SessionClose (vlc_tls_t *tls) ...@@ -332,9 +325,7 @@ static void gnutls_SessionClose (vlc_tls_t *tls)
{ {
gnutls_session_t session = tls->sys; gnutls_session_t session = tls->sys;
if (tls->sock.p_sys != NULL) gnutls_bye (session, GNUTLS_SHUT_RDWR);
gnutls_bye (session, GNUTLS_SHUT_WR);
gnutls_deinit (session); gnutls_deinit (session);
} }
...@@ -375,17 +366,11 @@ static int gnutls_ClientHandshake (vlc_tls_t *tls, const char *host, ...@@ -375,17 +366,11 @@ static int gnutls_ClientHandshake (vlc_tls_t *tls, const char *host,
{ {
msg_Err (tls, "Certificate verification error: %s", msg_Err (tls, "Certificate verification error: %s",
gnutls_strerror (val)); gnutls_strerror (val));
failure:
gnutls_bye (session, GNUTLS_SHUT_RDWR);
return -1; return -1;
} }
if (status == 0) if (status == 0) /* Good certificate */
{ /* Good certificate */
success:
tls->sock.p_sys = tls;
return 0; return 0;
}
/* Bad certificate */ /* Bad certificate */
gnutls_datum_t desc; gnutls_datum_t desc;
...@@ -402,7 +387,7 @@ success: ...@@ -402,7 +387,7 @@ success:
status &= ~GNUTLS_CERT_UNEXPECTED_OWNER; /* mismatched hostname */ status &= ~GNUTLS_CERT_UNEXPECTED_OWNER; /* mismatched hostname */
if (status != 0 || host == NULL) if (status != 0 || host == NULL)
goto failure; /* Really bad certificate */ return -1; /* Really bad certificate */
/* Look up mismatching certificate in store */ /* Look up mismatching certificate in store */
const gnutls_datum_t *datum; const gnutls_datum_t *datum;
...@@ -412,7 +397,7 @@ success: ...@@ -412,7 +397,7 @@ success:
if (datum == NULL || count == 0) if (datum == NULL || count == 0)
{ {
msg_Err (tls, "Peer certificate not available"); msg_Err (tls, "Peer certificate not available");
goto failure; return -1;
} }
msg_Dbg (tls, "%u certificate(s) in the list", count); msg_Dbg (tls, "%u certificate(s) in the list", count);
...@@ -423,7 +408,7 @@ success: ...@@ -423,7 +408,7 @@ success:
{ {
case 0: case 0:
msg_Dbg (tls, "certificate key match for %s", host); msg_Dbg (tls, "certificate key match for %s", host);
goto success; return 0;
case GNUTLS_E_NO_CERTIFICATE_FOUND: case GNUTLS_E_NO_CERTIFICATE_FOUND:
msg_Dbg (tls, "no known certificates for %s", host); msg_Dbg (tls, "no known certificates for %s", host);
msg = N_("However the security certificate presented by the " msg = N_("However the security certificate presented by the "
...@@ -439,7 +424,7 @@ success: ...@@ -439,7 +424,7 @@ success:
default: default:
msg_Err (tls, "certificate key match error for %s: %s", host, msg_Err (tls, "certificate key match error for %s: %s", host,
gnutls_strerror (val)); gnutls_strerror (val));
goto failure; return -1;
} }
if (dialog_Question (tls, _("Insecure site"), if (dialog_Question (tls, _("Insecure site"),
...@@ -449,17 +434,17 @@ success: ...@@ -449,17 +434,17 @@ success:
"If in doubt, abort now.\n"), "If in doubt, abort now.\n"),
_("Abort"), _("View certificate"), NULL, _("Abort"), _("View certificate"), NULL,
vlc_gettext (msg), host) != 2) vlc_gettext (msg), host) != 2)
goto failure; return -1;
gnutls_x509_crt_t cert; gnutls_x509_crt_t cert;
if (gnutls_x509_crt_init (&cert)) if (gnutls_x509_crt_init (&cert))
goto failure; return -1;
if (gnutls_x509_crt_import (cert, datum, GNUTLS_X509_FMT_DER) if (gnutls_x509_crt_import (cert, datum, GNUTLS_X509_FMT_DER)
|| gnutls_x509_crt_print (cert, GNUTLS_CRT_PRINT_ONELINE, &desc)) || gnutls_x509_crt_print (cert, GNUTLS_CRT_PRINT_ONELINE, &desc))
{ {
gnutls_x509_crt_deinit (cert); gnutls_x509_crt_deinit (cert);
goto failure; return -1;
} }
gnutls_x509_crt_deinit (cert); gnutls_x509_crt_deinit (cert);
...@@ -482,9 +467,9 @@ success: ...@@ -482,9 +467,9 @@ success:
if (val) if (val)
msg_Err (tls, "cannot store X.509 certificate: %s", msg_Err (tls, "cannot store X.509 certificate: %s",
gnutls_strerror (val)); gnutls_strerror (val));
goto success; return 0;
} }
goto failure; return -1;
} }
/** /**
...@@ -558,12 +543,8 @@ static int gnutls_ServerSessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *tls, ...@@ -558,12 +543,8 @@ static int gnutls_ServerSessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *tls,
static int gnutls_ServerHandshake (vlc_tls_t *tls, const char *host, static int gnutls_ServerHandshake (vlc_tls_t *tls, const char *host,
const char *service, char **restrict alp) const char *service, char **restrict alp)
{ {
int val = gnutls_ContinueHandshake (tls, alp);
if (val == 0)
tls->sock.p_sys = tls;
(void) host; (void) service; (void) host; (void) service;
return val; return gnutls_ContinueHandshake (tls, alp);
} }
/** /**
......
...@@ -422,9 +422,8 @@ static int st_Handshake (vlc_tls_t *session, const char *host, ...@@ -422,9 +422,8 @@ static int st_Handshake (vlc_tls_t *session, const char *host,
/** /**
* Sends data through a TLS session. * Sends data through a TLS session.
*/ */
static int st_Send (void *opaque, const void *buf, size_t length) static ssize_t st_Send (vlc_tls_t *session, const void *buf, size_t length)
{ {
vlc_tls_t *session = opaque;
vlc_tls_sys_t *sys = session->sys; vlc_tls_sys_t *sys = session->sys;
OSStatus ret = noErr; OSStatus ret = noErr;
...@@ -476,9 +475,8 @@ static int st_Send (void *opaque, const void *buf, size_t length) ...@@ -476,9 +475,8 @@ static int st_Send (void *opaque, const void *buf, size_t length)
/** /**
* Receives data through a TLS session. * Receives data through a TLS session.
*/ */
static int st_Recv (void *opaque, void *buf, size_t length) static ssize_t st_Recv (vlc_tls_t *session, void *buf, size_t length)
{ {
vlc_tls_t *session = opaque;
vlc_tls_sys_t *sys = session->sys; vlc_tls_sys_t *sys = session->sys;
size_t actualSize; size_t actualSize;
...@@ -542,9 +540,8 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session, ...@@ -542,9 +540,8 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
sys->p_context = NULL; sys->p_context = NULL;
session->sys = sys; session->sys = sys;
session->sock.p_sys = session; session->send = st_Send;
session->sock.pf_send = st_Send; session->recv = st_Recv;
session->sock.pf_recv = st_Recv;
crd->handshake = st_Handshake; crd->handshake = st_Handshake;
SSLContextRef p_context = NULL; SSLContextRef p_context = NULL;
......
...@@ -235,7 +235,7 @@ int vlc_tls_Read(vlc_tls_t *session, void *buf, size_t len, bool waitall) ...@@ -235,7 +235,7 @@ int vlc_tls_Read(vlc_tls_t *session, void *buf, size_t len, bool waitall)
return -1; return -1;
} }
ssize_t val = session->sock.pf_recv(session, buf, len); ssize_t val = session->recv(session, buf, len);
if (val > 0) if (val > 0)
{ {
if (!waitall) if (!waitall)
...@@ -268,7 +268,7 @@ int vlc_tls_Write(vlc_tls_t *session, const void *buf, size_t len) ...@@ -268,7 +268,7 @@ int vlc_tls_Write(vlc_tls_t *session, const void *buf, size_t len)
return -1; return -1;
} }
ssize_t val = session->sock.pf_send(session, buf, len); ssize_t val = session->send(session, buf, len);
if (val > 0) if (val > 0)
{ {
buf = ((const char *)buf) + val; buf = ((const char *)buf) + val;
......
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