From: DINH V. H. <ho...@us...> - 2005-03-12 01:16:36
|
Update of /cvsroot/libetpan/libetpan/src/data-types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15676/src/data-types Modified Files: mailstream_ssl.c mailsem.c Log Message: support for GNUTLS, non-reentrant support is improved, fixed a false error in cached IMAP driver Index: mailstream_ssl.c =================================================================== RCS file: /cvsroot/libetpan/libetpan/src/data-types/mailstream_ssl.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- mailstream_ssl.c 21 Nov 2004 21:53:31 -0000 1.18 +++ mailstream_ssl.c 12 Mar 2005 01:16:25 -0000 1.19 @@ -61,7 +61,12 @@ /* mailstream_low, ssl */ #ifdef USE_SSL +#ifndef USE_GNUTLS #include <openssl/ssl.h> +#else +#include <errno.h> +#include <gnutls/openssl.h> +#endif #ifdef LIBETPAN_REENTRANT #include <pthread.h> #endif @@ -116,7 +121,7 @@ #ifdef LIBETPAN_REENTRANT pthread_mutex_lock(&ssl_lock); -#endif +#endif if (!ssl_init_done) { SSL_library_init(); ssl_init_done = 1; @@ -136,7 +141,9 @@ if (SSL_set_fd(ssl_conn, fd) == 0) goto free_ssl_conn; +#ifndef USE_GNUTLS SSL_set_read_ahead(ssl_conn, 1); +#endif r = SSL_connect(ssl_conn); if (r <= 0) @@ -252,11 +259,35 @@ int ssl_r; fd_set fds_read; struct timeval timeout; +#ifdef USE_GNUTLS + fd_set fds_excp; +#endif + +#ifdef USE_GNUTLS + timeout = mailstream_network_delay; + + FD_ZERO(&fds_read); + FD_SET(ssl_data->fd, &fds_read); + FD_ZERO(&fds_excp); + FD_SET(ssl_data->fd, &fds_excp); + r = select(ssl_data->fd + 1, &fds_read, NULL, &fds_excp, &timeout); + if (r==0) { + return -1; + } + if (FD_ISSET(ssl_data->fd, &fds_excp)) + return -1; + if (!FD_ISSET(ssl_data->fd, &fds_read)) + return 0; +#endif r = SSL_read(ssl_data->ssl_conn, buf, count); if (r > 0) return r; +#ifdef USE_GNUTLS + if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) + return r; +#else ssl_r = SSL_get_error(ssl_data->ssl_conn, r); switch (ssl_r) { case SSL_ERROR_NONE: @@ -278,6 +309,7 @@ default: return r; } +#endif } } @@ -287,6 +319,32 @@ struct mailstream_ssl_data * ssl_data; ssl_data = (struct mailstream_ssl_data *) s->data; +#ifdef USE_GNUTLS + { + fd_set fds_write; + fd_set fds_excp; + struct timeval timeout; + int r; + + timeout = mailstream_network_delay; + + FD_ZERO(&fds_write); + FD_SET(ssl_data->fd, &fds_write); + FD_ZERO(&fds_excp); + FD_SET(ssl_data->fd, &fds_excp); + + r = select(ssl_data->fd + 1, NULL, &fds_write, &fds_excp, &timeout); + if (r == 0) + return -1; + + if (FD_ISSET(ssl_data->fd, &fds_excp)) + return -1; + + if (!FD_ISSET(ssl_data->fd, &fds_write)) + return 0; + } +#endif + return SSL_write(ssl_data->ssl_conn, buf, count); } #endif Index: mailsem.c =================================================================== RCS file: /cvsroot/libetpan/libetpan/src/data-types/mailsem.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- mailsem.c 4 Mar 2005 16:13:13 -0000 1.5 +++ mailsem.c 12 Mar 2005 01:16:25 -0000 1.6 @@ -34,7 +34,6 @@ */ #include "mailsem.h" -#include <semaphore.h> #include <stdlib.h> #include <stdio.h> #include <sys/stat.h> @@ -42,6 +41,10 @@ #include <fcntl.h> #include <unistd.h> +#ifdef LIBETPAN_REENTRANT +#include <semaphore.h> +#endif + enum { SEMKIND_SEMOPEN, SEMKIND_SEMINIT, @@ -51,6 +54,7 @@ struct mailsem * mailsem_new(void) { +#ifdef LIBETPAN_REENTRANT struct mailsem * sem; int r; @@ -92,10 +96,14 @@ free(sem); err: return NULL; +#else + return NULL; +#endif } void mailsem_free(struct mailsem * sem) { +#ifdef LIBETPAN_REENTRANT if (sem->sem_kind == SEMKIND_SEMOPEN) { char name[SEMNAME_LEN]; pid_t pid; @@ -113,14 +121,23 @@ free(sem->sem_sem); } free(sem); +#endif } int mailsem_up(struct mailsem * sem) { +#ifdef LIBETPAN_REENTRANT return sem_post((sem_t *) sem->sem_sem); +#else + return -1; +#endif } int mailsem_down(struct mailsem * sem) { +#ifdef LIBETPAN_REENTRANT return sem_wait((sem_t *) sem->sem_sem); +#else + return -1; +#endif } |