diff options
-rw-r--r-- | lib/gnutls_buffers.c | 19 | ||||
-rw-r--r-- | lib/gnutls_global.c | 80 | ||||
-rw-r--r-- | lib/gnutls_int.h | 11 |
3 files changed, 59 insertions, 51 deletions
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c index 7d98db633c..8e977110ec 100644 --- a/lib/gnutls_buffers.c +++ b/lib/gnutls_buffers.c @@ -38,9 +38,6 @@ # include <io_debug.h> #endif -extern ssize_t (*_gnutls_pull_func)( SOCKET, void*, size_t); -extern ssize_t (*_gnutls_push_func)( SOCKET,const void*, size_t); - /* Buffers received packets of type APPLICATION DATA and * HANDSHAKE DATA. */ @@ -152,7 +149,7 @@ int gnutls_getDataFromBuffer(ContentType type, GNUTLS_STATE state, char *data, i * * Flags are only used if the default recv() function is being used. */ -static ssize_t _gnutls_read(SOCKET fd, void *iptr, size_t sizeOfPtr, int flags) +static ssize_t _gnutls_read( SOCKET fd, GNUTLS_STATE state, void *iptr, size_t sizeOfPtr, int flags) { size_t left; ssize_t i=0; @@ -165,10 +162,10 @@ static ssize_t _gnutls_read(SOCKET fd, void *iptr, size_t sizeOfPtr, int flags) left = sizeOfPtr; while (left > 0) { - if (_gnutls_pull_func==NULL) + if (state->gnutls_internals._gnutls_pull_func==NULL) i = recv(fd, &ptr[sizeOfPtr-left], left, flags); else - i = _gnutls_pull_func(fd, &ptr[sizeOfPtr-left], left); + i = state->gnutls_internals._gnutls_pull_func(fd, &ptr[sizeOfPtr-left], left); if (i < 0) { #ifdef READ_DEBUG @@ -248,7 +245,7 @@ int ret, sum; /* this was already read by using MSG_PEEK - so it shouldn't fail */ sum = 0; do { /* we need this to finish now */ - ret = _gnutls_read( cd, peek, RCVLOWAT-sum, 0); + ret = _gnutls_read( cd, state, peek, RCVLOWAT-sum, 0); if (ret > 0) sum+=ret; } while( ret==GNUTLS_E_INTERRUPTED || ret==GNUTLS_E_AGAIN || sum < RCVLOWAT); @@ -332,7 +329,7 @@ ssize_t _gnutls_read_buffered( int fd, GNUTLS_STATE state, opaque **iptr, size_t /* READ DATA - but leave RCVLOWAT bytes in the kernel buffer. */ if ( recvdata - recvlowat > 0) { - ret = _gnutls_read( fd, &buf[buf_pos], recvdata - recvlowat, 0); + ret = _gnutls_read( fd, state, &buf[buf_pos], recvdata - recvlowat, 0); /* return immediately if we got an interrupt or eagain * error. @@ -359,7 +356,7 @@ ssize_t _gnutls_read_buffered( int fd, GNUTLS_STATE state, opaque **iptr, size_t * select think, that the socket is ready for reading */ if (ret == (recvdata - recvlowat) && recvlowat > 0) { - ret2 = _gnutls_read( fd, &buf[buf_pos], recvlowat, MSG_PEEK); + ret2 = _gnutls_read( fd, state, &buf[buf_pos], recvlowat, MSG_PEEK); if (ret2 < 0 && gnutls_is_fatal_error(ret2)==0) { return ret2; @@ -460,10 +457,10 @@ ssize_t _gnutls_write_buffered(SOCKET fd, GNUTLS_STATE state, const void *iptr, left = n; while (left > 0) { - if (_gnutls_push_func==NULL) + if (state->gnutls_internals._gnutls_push_func==NULL) i = send(fd, &ptr[n-left], left, 0); else - i = _gnutls_push_func(fd, &ptr[n-left], left); + i = state->gnutls_internals._gnutls_push_func(fd, &ptr[n-left], left); if (i == -1) { if (errno == EAGAIN || errno == EINTR) { diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c index 9567fc4154..d61776dac8 100644 --- a/lib/gnutls_global.c +++ b/lib/gnutls_global.c @@ -45,12 +45,8 @@ extern const static_asn pkcs1_asn1_tab[]; extern const static_asn pkix_asn1_tab[]; -typedef ssize_t (*PULL_FUNC)(SOCKET, void*, size_t); -typedef ssize_t (*PUSH_FUNC)(SOCKET, const void*, size_t); typedef void (*LOG_FUNC)( const char*); -PULL_FUNC _gnutls_pull_func; -PUSH_FUNC _gnutls_push_func; LOG_FUNC _gnutls_log_func; static node_asn *PKIX1_ASN; @@ -64,39 +60,6 @@ node_asn* _gnutls_get_pkcs() { return PKCS1_ASN; } -/** - * gnutls_global_set_pull_func - This function sets a read like function - * @pull_func: it's a function like read - * - * This is the function where you set a function for gnutls - * to receive data. Normaly, if you use berkeley style sockets, - * you may not use this function since the default (recv(2)) will - * probably be ok. - * This function should be called once and after gnutls_global_init(). - * PULL_FUNC is of the form, - * ssize_t (*PULL_FUNC)(SOCKET, const void*, size_t); - **/ -void gnutls_global_set_pull_func( PULL_FUNC pull_func) { - _gnutls_pull_func = pull_func; -} - -/** - * gnutls_global_set_push_func - This function sets the function to send data - * @push_func: it's a function like write - * - * This is the function where you set a push function for gnutls - * to use in order to send data. If you are going to use berkeley style - * sockets, you may not use this function since - * the default (send(2)) will probably be ok. Otherwise you should - * specify this function for gnutls to be able to send data. - * - * This function should be called once and after gnutls_global_init(). - * PUSH_FUNC is of the form, - * ssize_t (*PUSH_FUNC)(SOCKET, const void*, size_t); - **/ -void gnutls_global_set_push_func( PUSH_FUNC push_func) { - _gnutls_push_func = push_func; -} /** * gnutls_global_set_log_func - This function sets the logging function @@ -149,8 +112,6 @@ int gnutls_global_init() /* set default recv/send functions */ - _gnutls_pull_func = NULL; - _gnutls_push_func = NULL; gnutls_global_set_log_func( dlog); /* initialize parser @@ -235,3 +196,44 @@ static Sigfunc * #endif /* HAVE_SIGACTION */ } #endif /* USE_SIGNALS */ + + +/* These functions should be elsewere. Kept here for + * historical reasons. + */ + +/** + * gnutls_set_pull_func - This function sets a read like function + * @pull_func: it's a function like read + * @state: gnutls state + * + * This is the function where you set a function for gnutls + * to receive data. Normaly, if you use berkeley style sockets, + * you may not use this function since the default (recv(2)) will + * probably be ok. + * This function should be called once and after gnutls_global_init(). + * PULL_FUNC is of the form, + * ssize_t (*PULL_FUNC)(SOCKET, const void*, size_t); + **/ +void gnutls_set_pull_func( GNUTLS_STATE state, PULL_FUNC pull_func) { + state->gnutls_internals._gnutls_pull_func = pull_func; +} + +/** + * gnutls_set_push_func - This function sets the function to send data + * @push_func: it's a function like write + * @state: gnutls state + * + * This is the function where you set a push function for gnutls + * to use in order to send data. If you are going to use berkeley style + * sockets, you may not use this function since + * the default (send(2)) will probably be ok. Otherwise you should + * specify this function for gnutls to be able to send data. + * + * This function should be called once and after gnutls_global_init(). + * PUSH_FUNC is of the form, + * ssize_t (*PUSH_FUNC)(SOCKET, const void*, size_t); + **/ +void gnutls_set_push_func( GNUTLS_STATE state, PUSH_FUNC push_func) { + state->gnutls_internals._gnutls_push_func = push_func; +} diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 8413b8937e..7577fcb546 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -143,9 +143,14 @@ typedef enum CompressionMethod { GNUTLS_NULL_COMPRESSION=1, GNUTLS_ZLIB } Compre typedef enum ValidSession { VALID_TRUE, VALID_FALSE } ValidSession; typedef enum ResumableSession { RESUME_TRUE, RESUME_FALSE } ResumableSession; - /* STATE (stop) */ + +/* Pull & Push functions defines: + */ +typedef ssize_t (*PULL_FUNC)(SOCKET, void*, size_t); +typedef ssize_t (*PUSH_FUNC)(SOCKET, const void*, size_t); + typedef struct { KXAlgorithm algorithm; void* credentials; @@ -416,6 +421,10 @@ typedef struct { int (*x509_client_cert_callback)(void*,void*,int, void*, int); gnutls_cert peer_cert; int max_handshake_data_buffer_size; + /* PUSH & PULL functions. + */ + PULL_FUNC _gnutls_pull_func; + PUSH_FUNC _gnutls_push_func; } GNUTLS_INTERNALS; struct GNUTLS_STATE_INT { |