# 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.
*/
*
* 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;
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
/* 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);
/* 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.
* 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;
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) {
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;
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
/* set default recv/send functions
*/
- _gnutls_pull_func = NULL;
- _gnutls_push_func = NULL;
gnutls_global_set_log_func( dlog);
/* initialize parser
#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;
+}
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;
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 {