diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-02-16 09:53:03 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-02-16 09:56:10 +0100 |
commit | 1216eabdcb81b9d13fb3c422b411a8c1cd700ee7 (patch) | |
tree | 8aa3e61e9e8d7a2cfb9b18f4767ba8591fd73d27 | |
parent | b24ab4e5c7219c4d5b4ae3255fad31a8731c9e69 (diff) | |
download | gnutls-1216eabdcb81b9d13fb3c422b411a8c1cd700ee7.tar.gz |
Added convenience functions to avoid ugly casting in simple programs.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/cha-gtls-app.texi | 18 | ||||
-rw-r--r-- | doc/examples/ex-cert-select-pkcs11.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-cert-select.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-anon.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-dtls.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-psk.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-resume.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-srp.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-client-x509.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-serv-anon.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-serv-pgp.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-serv-psk.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-serv-srp.c | 2 | ||||
-rw-r--r-- | doc/examples/ex-serv-x509.c | 2 | ||||
-rw-r--r-- | lib/gnutls_record.c | 88 | ||||
-rw-r--r-- | lib/includes/gnutls/gnutls.h.in | 6 | ||||
-rw-r--r-- | lib/libgnutls.map | 16 | ||||
-rw-r--r-- | src/cli.c | 4 | ||||
-rw-r--r-- | src/serv.c | 4 |
20 files changed, 125 insertions, 40 deletions
@@ -11,6 +11,9 @@ a PKCS #12 file from an encrypted key file. Reported by Yan Fiz. ** API and ABI modifications: gnutls_handshake_set_random: Added +gnutls_transport_set_int2: Added +gnutls_transport_get_int2: Added +gnutls_transport_get_int: Added gnutls_record_cork: Exported gnutls_record_uncork: Exported diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi index 9a7ea4fafb..0f264def59 100644 --- a/doc/cha-gtls-app.texi +++ b/doc/cha-gtls-app.texi @@ -608,19 +608,25 @@ The initialization functions for the credentials are shown below. The next step is to setup the underlying transport layer details. The Berkeley sockets are implicitly used by GnuTLS, thus a -call to @funcref{gnutls_transport_set_ptr2} would be sufficient to -specify the socket descriptor. +call to @funcref{gnutls_transport_set_int} would be sufficient to +specify the socket descriptor. -@showfuncdesc{gnutls_transport_set_ptr2} - -@showfuncA{gnutls_transport_set_ptr} +@showfuncB{gnutls_transport_set_int,gnutls_transport_set_int2} If however another transport layer than TCP is selected, then -the following functions have to be specified. +a pointer should be used instead to express the parameter to be +passed to custom functions. In that case the following functions should +be used instead. + +@showfuncB{gnutls_transport_set_ptr,gnutls_transport_set_ptr2} + +Moreover all of the following push and pull callbacks should be set. @showfuncdesc{gnutls_transport_set_push_function} @showfuncdesc{gnutls_transport_set_vec_push_function} @showfuncdesc{gnutls_transport_set_pull_function} +@showfuncdesc{gnutls_transport_set_pull_timeout_function} + The functions above accept a callback function which should return the number of bytes written, or -1 on diff --git a/doc/examples/ex-cert-select-pkcs11.c b/doc/examples/ex-cert-select-pkcs11.c index e867926b87..a437a51507 100644 --- a/doc/examples/ex-cert-select-pkcs11.c +++ b/doc/examples/ex-cert-select-pkcs11.c @@ -114,7 +114,7 @@ main (void) */ sd = tcp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); /* Perform the TLS handshake */ diff --git a/doc/examples/ex-cert-select.c b/doc/examples/ex-cert-select.c index 7b5173425a..b4ec2b1605 100644 --- a/doc/examples/ex-cert-select.c +++ b/doc/examples/ex-cert-select.c @@ -129,7 +129,7 @@ main (void) */ sd = tcp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); /* Perform the TLS handshake */ diff --git a/doc/examples/ex-client-anon.c b/doc/examples/ex-client-anon.c index a85071bbce..3d4d3afa08 100644 --- a/doc/examples/ex-client-anon.c +++ b/doc/examples/ex-client-anon.c @@ -51,7 +51,7 @@ main (void) */ sd = tcp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); gnutls_handshake_set_timeout (session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); /* Perform the TLS handshake diff --git a/doc/examples/ex-client-dtls.c b/doc/examples/ex-client-dtls.c index a7c363882f..026cb7d082 100644 --- a/doc/examples/ex-client-dtls.c +++ b/doc/examples/ex-client-dtls.c @@ -65,7 +65,7 @@ main (void) /* connect to the peer */ sd = udp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); /* set the connection MTU */ gnutls_dtls_set_mtu (session, 1000); diff --git a/doc/examples/ex-client-psk.c b/doc/examples/ex-client-psk.c index a68944a49b..4ebff50dcd 100644 --- a/doc/examples/ex-client-psk.c +++ b/doc/examples/ex-client-psk.c @@ -61,7 +61,7 @@ main (void) */ sd = tcp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); gnutls_handshake_set_timeout (session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); /* Perform the TLS handshake diff --git a/doc/examples/ex-client-resume.c b/doc/examples/ex-client-resume.c index de3b403857..1842c5e7a1 100644 --- a/doc/examples/ex-client-resume.c +++ b/doc/examples/ex-client-resume.c @@ -59,7 +59,7 @@ main (void) free (session_data); } - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); gnutls_handshake_set_timeout (session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); /* Perform the TLS handshake diff --git a/doc/examples/ex-client-srp.c b/doc/examples/ex-client-srp.c index 112e9f0476..7b4989608c 100644 --- a/doc/examples/ex-client-srp.c +++ b/doc/examples/ex-client-srp.c @@ -58,7 +58,7 @@ main (void) gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred); gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cert_cred); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); gnutls_handshake_set_timeout (session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); /* Perform the TLS handshake diff --git a/doc/examples/ex-client-x509.c b/doc/examples/ex-client-x509.c index 9295f981d5..acd6593d47 100644 --- a/doc/examples/ex-client-x509.c +++ b/doc/examples/ex-client-x509.c @@ -77,7 +77,7 @@ int main (void) */ sd = tcp_connect (); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); gnutls_handshake_set_timeout (session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); /* Perform the TLS handshake diff --git a/doc/examples/ex-serv-anon.c b/doc/examples/ex-serv-anon.c index a46fe9c80b..727ed16bd6 100644 --- a/doc/examples/ex-serv-anon.c +++ b/doc/examples/ex-serv-anon.c @@ -99,7 +99,7 @@ main (void) inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); do { diff --git a/doc/examples/ex-serv-pgp.c b/doc/examples/ex-serv-pgp.c index aa4f8457c2..78e4c59e1f 100644 --- a/doc/examples/ex-serv-pgp.c +++ b/doc/examples/ex-serv-pgp.c @@ -116,7 +116,7 @@ main (void) inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); ret = gnutls_handshake (session); if (ret < 0) { diff --git a/doc/examples/ex-serv-psk.c b/doc/examples/ex-serv-psk.c index 498beeef02..2e025ca9ca 100644 --- a/doc/examples/ex-serv-psk.c +++ b/doc/examples/ex-serv-psk.c @@ -140,7 +140,7 @@ main (void) inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); ret = gnutls_handshake (session); if (ret < 0) { diff --git a/doc/examples/ex-serv-srp.c b/doc/examples/ex-serv-srp.c index c3dcae8455..3a95edd172 100644 --- a/doc/examples/ex-serv-srp.c +++ b/doc/examples/ex-serv-srp.c @@ -102,7 +102,7 @@ main (void) inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); do { diff --git a/doc/examples/ex-serv-x509.c b/doc/examples/ex-serv-x509.c index 3f6c305b6e..8929242070 100644 --- a/doc/examples/ex-serv-x509.c +++ b/doc/examples/ex-serv-x509.c @@ -122,7 +122,7 @@ main (void) inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); - gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); + gnutls_transport_set_int (session, sd); do { diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 025485ef3a..cfcdf351d5 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -111,6 +111,7 @@ gnutls_record_set_max_empty_records (gnutls_session_t session, const unsigned in * Used to set the first argument of the transport function (for push * and pull callbacks). In berkeley style sockets this function will set the * connection descriptor. + * **/ void gnutls_transport_set_ptr (gnutls_session_t session, @@ -141,6 +142,49 @@ gnutls_transport_set_ptr2 (gnutls_session_t session, } /** + * gnutls_transport_set_int2: + * @session: is a #gnutls_session_t structure. + * @recv_int: is the value for the pull function + * @send_int: is the value for the push function + * + * Used to set the first argument of the transport function (for push + * and pull callbacks), when using the berkeley style sockets. + * With this function you can set two different + * pointers for receiving and sending. + * + * Since: 3.1.9 + **/ +void +gnutls_transport_set_int2 (gnutls_session_t session, + int recv_int, + int send_int) +{ + session->internals.transport_send_ptr = (gnutls_transport_ptr_t)(long)send_int; + session->internals.transport_recv_ptr = (gnutls_transport_ptr_t)(long)recv_int; +} + +#if 0 +/* this will be a macro */ +/** + * gnutls_transport_set_int: + * @session: is a #gnutls_session_t structure. + * @i: is the value. + * + * Used to set the first argument of the transport function (for push + * and pull callbacks) for berkeley style sockets. + * + * Since: 3.1.9 + * + **/ +void +gnutls_transport_set_ptr (gnutls_session_t session, int i) +{ + session->internals.transport_recv_ptr = (gnutls_transport_ptr_t)(long)i; + session->internals.transport_send_ptr = (gnutls_transport_ptr_t)(long)i; +} +#endif + +/** * gnutls_transport_get_ptr: * @session: is a #gnutls_session_t structure. * @@ -177,6 +221,46 @@ gnutls_transport_get_ptr2 (gnutls_session_t session, } /** + * gnutls_transport_get_int2: + * @session: is a #gnutls_session_t structure. + * @recv_int: will hold the value for the pull function + * @send_int: will hold the value for the push function + * + * Used to get the arguments of the transport functions (like PUSH + * and PULL). These should have been set using + * gnutls_transport_set_int2(). + * + * Since: 3.1.9 + **/ +void +gnutls_transport_get_int2 (gnutls_session_t session, + int * recv_int, + int * send_int) +{ + + *recv_int = (long)session->internals.transport_recv_ptr; + *send_int = (long)session->internals.transport_send_ptr; +} + +/** + * gnutls_transport_get_int: + * @session: is a #gnutls_session_t structure. + * + * Used to get the first argument of the transport function (like + * PUSH and PULL). This must have been set using + * gnutls_transport_set_int(). + * + * Returns: The first argument of the transport function. + * + * Since: 3.1.9 + **/ +int +gnutls_transport_get_int (gnutls_session_t session) +{ + return (long)session->internals.transport_recv_ptr; +} + +/** * gnutls_bye: * @session: is a #gnutls_session_t structure. * @how: is an integer @@ -1325,7 +1409,7 @@ gnutls_record_send (gnutls_session_t session, const void *data, * All queued records will be sent when gnutls_uncork() is called, or * when the maximum record size is reached. * - * Since: 3.1.7 + * Since: 3.1.9 **/ void gnutls_record_cork (gnutls_session_t session) @@ -1347,7 +1431,7 @@ gnutls_record_cork (gnutls_session_t session) * Returns: On success the number of transmitted data is returned, or * otherwise a negative error code. * - * Since: 3.1.7 + * Since: 3.1.9 **/ int gnutls_record_uncork (gnutls_session_t session, unsigned int flags) diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index cc49f8b722..bb36b1bcaf 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -1409,6 +1409,12 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session); const giovec_t * iov, int iovcnt); typedef int (*gnutls_errno_func) (gnutls_transport_ptr_t); + + void gnutls_transport_set_int2 (gnutls_session_t session, int r, int s); + #define gnutls_transport_set_int(s, i) gnutls_transport_set_int2(s, i, i) + + void gnutls_transport_get_int2 (gnutls_session_t session, int * r, int *s); + int gnutls_transport_get_int (gnutls_session_t session); void gnutls_transport_set_ptr (gnutls_session_t session, gnutls_transport_ptr_t ptr); diff --git a/lib/libgnutls.map b/lib/libgnutls.map index e5bd6e8059..4c314780f3 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -889,19 +889,9 @@ GNUTLS_3_1_0 { gnutls_handshake_set_server_random; gnutls_record_cork; gnutls_record_uncork; - xssl_deinit; - xssl_flush; - xssl_read; - xssl_getdelim; - xssl_write; - xssl_printf; - xssl_sinit; - xssl_client_init; - xssl_server_init; - xssl_get_session; - xssl_get_verify_status; - xssl_cred_init; - xssl_cred_deinit; + gnutls_transport_set_int2; + gnutls_transport_get_int2; + gnutls_transport_get_int; } GNUTLS_3_0_0; GNUTLS_PRIVATE { @@ -1246,9 +1246,7 @@ do_handshake (socket_st * socket) { int ret; - gnutls_transport_set_ptr (socket->session, - (gnutls_transport_ptr_t) - gl_fd_to_handle (socket->fd)); + gnutls_transport_set_int (socket->session, socket->fd); do { gnutls_handshake_set_timeout( socket->session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); diff --git a/src/serv.c b/src/serv.c index 3fc9845c0d..5bab0bc31b 100644 --- a/src/serv.c +++ b/src/serv.c @@ -1296,9 +1296,7 @@ tcp_server (const char *name, int port) j->fd = accept_fd; j->tls_session = tls_session; - gnutls_transport_set_ptr (tls_session, - (gnutls_transport_ptr_t) - gl_fd_to_handle (accept_fd)); + gnutls_transport_set_ptr (tls_session, accept_fd); j->handshake_ok = 0; if (verbose != 0) |