specific timeout for each connection

dvh-chacham15-master
DINH Viet Hoa 2013-01-05 22:48:27 -08:00
parent 527aa19a45
commit e4bec41000
33 changed files with 347 additions and 88 deletions

View File

@ -103,7 +103,7 @@ static int verify_sock_errors(int s)
}
#endif
static int wait_connect(int s, int r)
static int wait_connect(int s, int r, time_t timeout_seconds)
{
fd_set fds;
struct timeval timeout;
@ -123,8 +123,14 @@ static int wait_connect(int s, int r)
FD_ZERO(&fds);
FD_SET(s, &fds);
timeout = mailstream_network_delay;
/* TODO: how to cancel this ? */
if (timeout_seconds == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = timeout_seconds;
timeout.tv_usec = 0;
}
/* TODO: how to cancel this ? -> could be cancelled using a cancel fd */
r = select(s + 1, NULL, &fds, NULL, &timeout);
if (r <= 0) {
return -1;
@ -143,8 +149,19 @@ int mail_tcp_connect(const char * server, uint16_t port)
return mail_tcp_connect_with_local_address(server, port, NULL, 0);
}
int mail_tcp_connect_timeout(const char * server, uint16_t port, time_t timeout)
{
return mail_tcp_connect_with_local_address_timeout(server, port, NULL, 0, timeout);
}
int mail_tcp_connect_with_local_address(const char * server, uint16_t port,
const char * local_address, uint16_t local_port)
{
return mail_tcp_connect_with_local_address_timeout(server, port, local_address, local_port, 0);
}
int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t port,
const char * local_address, uint16_t local_port, time_t timeout)
{
#ifndef HAVE_IPV6
struct hostent * remotehost;
@ -197,7 +214,7 @@ int mail_tcp_connect_with_local_address(const char * server, uint16_t port,
}
r = connect(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
r = wait_connect(s, r);
r = wait_connect(s, r, timeout);
if (r == -1) {
goto close_socket;
}
@ -263,7 +280,7 @@ int mail_tcp_connect_with_local_address(const char * server, uint16_t port,
}
r = connect(s, ai->ai_addr, ai->ai_addrlen);
r = wait_connect(s, r);
r = wait_connect(s, r, timeout);
if (r != -1) {
r = verify_sock_errors(s);

View File

@ -40,6 +40,7 @@
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#include <time.h>
#ifdef __cplusplus
extern "C" {
@ -47,8 +48,11 @@ extern "C" {
uint16_t mail_get_service_port(const char * name, char * protocol);
int mail_tcp_connect(const char * server, uint16_t port);
int mail_tcp_connect_timeout(const char * server, uint16_t port, time_t timeout);
int mail_tcp_connect_with_local_address(const char * server, uint16_t port,
const char * local_address, uint16_t local_port);
int mail_tcp_connect_with_local_address_timeout(const char * server, uint16_t port,
const char * local_address, uint16_t local_port, time_t timeout);
#ifdef __cplusplus
}

View File

@ -181,16 +181,27 @@ static void cfstream_data_close(struct mailstream_cfstream_data * cfstream_data)
mailstream * mailstream_cfstream_open(const char * hostname, int16_t port)
{
return mailstream_cfstream_open_voip(hostname, port, mailstream_cfstream_voip_enabled);
return mailstream_cfstream_open_voip_timeout(hostname, port, 0, 0);
}
mailstream * mailstream_cfstream_open_timeout(const char * hostname, int16_t port, time_t timeout)
{
return mailstream_cfstream_open_voip_timeout(hostname, port, 0, timeout);
}
mailstream * mailstream_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled)
{
return mailstream_cfstream_open_voip_timeout(hostname, port, voip_enabled, 0);
}
mailstream * mailstream_cfstream_open_voip_timeout(const char * hostname, int16_t port, int voip_enabled,
time_t timeout)
{
#if HAVE_CFNETWORK
mailstream_low * low;
mailstream * s;
low = mailstream_low_cfstream_open_voip(hostname, port, voip_enabled);
low = mailstream_low_cfstream_open_voip_timeout(hostname, port, voip_enabled, timeout);
if (low == NULL) {
return NULL;
}
@ -416,10 +427,23 @@ static void writeStreamCallback(CFWriteStreamRef stream, CFStreamEventType event
mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t port)
{
return mailstream_low_cfstream_open_voip(hostname, port, mailstream_cfstream_voip_enabled);
return mailstream_low_cfstream_open_voip_timeout(hostname, port, mailstream_cfstream_voip_enabled, 0);
}
mailstream_low * mailstream_low_cfstream_open_timeout(const char * hostname, int16_t port,
time_t timeout)
{
return mailstream_low_cfstream_open_voip_timeout(hostname, port,
mailstream_cfstream_voip_enabled, timeout);
}
mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled)
{
return mailstream_low_cfstream_open_voip_timeout(hostname, port, voip_enabled, 0);
}
mailstream_low * mailstream_low_cfstream_open_voip_timeout(const char * hostname, int16_t port,
int voip_enabled, time_t timeout)
{
#if HAVE_CFNETWORK
mailstream_low * s;
@ -444,7 +468,8 @@ mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_
cfstream_data = cfstream_data_new(readStream, writeStream);
s = mailstream_low_new(cfstream_data, mailstream_cfstream_driver);
mailstream_low_set_timeout(s, timeout);
//fprintf(stderr, "open %s %i -> %p\n", hostname, port, s);
/* setup streams */
@ -722,7 +747,13 @@ static int wait_runloop(mailstream_low * s, int wait_state)
timeout.tv_usec = 0;
}
else {
timeout = mailstream_network_delay;
if (s->timeout == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = s->timeout;
timeout.tv_usec = 0;
}
}
delay = (CFTimeInterval) timeout.tv_sec + (CFTimeInterval) timeout.tv_usec / (CFTimeInterval) 1e6;

View File

@ -65,10 +65,18 @@ extern "C" {
extern mailstream_low_driver * mailstream_cfstream_driver;
mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t port);
mailstream * mailstream_cfstream_open(const char * hostname, int16_t port);
mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled);
mailstream * mailstream_cfstream_open_timeout(const char * hostname, int16_t port, time_t timeout);
mailstream * mailstream_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled);
mailstream * mailstream_cfstream_open_voip_timeout(const char * hostname, int16_t port, int voip_enabled,
time_t timeout);
mailstream_low * mailstream_low_cfstream_open(const char * hostname, int16_t port);
mailstream_low * mailstream_low_cfstream_open_timeout(const char * hostname, int16_t port,
time_t timeout);
mailstream_low * mailstream_low_cfstream_open_voip(const char * hostname, int16_t port, int voip_enabled);
mailstream_low * mailstream_low_cfstream_open_voip_timeout(const char * hostname, int16_t port,
int voip_enabled, time_t timeout);
/* first, set these settings */
void mailstream_cfstream_set_ssl_verification_mask(mailstream * s, int verification_mask);

View File

@ -166,6 +166,7 @@ mailstream_low * mailstream_low_new(void * data,
s->driver = driver;
s->privacy = 1;
s->identifier = NULL;
s->timeout = 0;
return s;
}
@ -292,3 +293,15 @@ const char * mailstream_low_get_identifier(mailstream_low * s)
{
return s->identifier;
}
void mailstream_low_set_timeout(mailstream_low * s,
time_t timeout)
{
s->timeout = timeout;
}
time_t mailstream_low_get_timeout(mailstream_low * s)
{
return s->timeout;
}

View File

@ -84,6 +84,11 @@ int mailstream_low_set_identifier(mailstream_low * s,
LIBETPAN_EXPORT
const char * mailstream_low_get_identifier(mailstream_low * s);
void mailstream_low_set_timeout(mailstream_low * s,
time_t timeout);
time_t mailstream_low_get_timeout(mailstream_low * s);
#ifdef __cplusplus
}
#endif

View File

@ -216,7 +216,13 @@ static ssize_t mailstream_low_socket_read(mailstream_low * s,
int max_fd;
#endif
timeout = mailstream_network_delay;
if (s->timeout == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = s->timeout;
timeout.tv_usec = 0;
}
FD_ZERO(&fds_read);
fd = mailstream_cancel_get_fd(socket_data->cancel);
@ -292,7 +298,13 @@ static ssize_t mailstream_low_socket_write(mailstream_low * s,
HANDLE event;
#endif
timeout = mailstream_network_delay;
if (s->timeout == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = s->timeout;
timeout.tv_usec = 0;
}
FD_ZERO(&fds_read);
fd = mailstream_cancel_get_fd(socket_data->cancel);
@ -343,6 +355,11 @@ static ssize_t mailstream_low_socket_write(mailstream_low * s,
/* mailstream */
mailstream * mailstream_socket_open(int fd)
{
return mailstream_socket_open_timeout(fd, 0);
}
mailstream * mailstream_socket_open_timeout(int fd, time_t timeout)
{
mailstream_low * low;
mailstream * s;
@ -350,6 +367,7 @@ mailstream * mailstream_socket_open(int fd)
low = mailstream_low_socket_open(fd);
if (low == NULL)
goto err;
mailstream_low_set_timeout(low, timeout);
s = mailstream_new(low, 8192);
if (s == NULL)

View File

@ -50,6 +50,7 @@ extern mailstream_low_driver * mailstream_socket_driver;
mailstream_low * mailstream_low_socket_open(int fd);
void mailstream_socket_set_use_read(mailstream * stream, int use_read);
mailstream * mailstream_socket_open(int fd);
mailstream * mailstream_socket_open_timeout(int fd, time_t timeout);
#ifdef __cplusplus
}

View File

@ -208,7 +208,7 @@ static int openssl_init_done = 0;
static void mailstream_openssl_reentrant_setup(void)
{
unsigned int i;
int i;
s_mutex_buf = (pthread_mutex_t *) malloc(CRYPTO_num_locks() * sizeof(* s_mutex_buf));
if(s_mutex_buf == NULL)
@ -299,7 +299,7 @@ static inline int mailstream_prepare_fd(int fd)
}
#endif
static int wait_SSL_connect(int s, int want_read)
static int wait_SSL_connect(int s, int want_read, time_t timeout_seconds)
{
fd_set fds;
struct timeval timeout;
@ -307,7 +307,13 @@ static int wait_SSL_connect(int s, int want_read)
FD_ZERO(&fds);
FD_SET(s, &fds);
timeout = mailstream_network_delay;
if (timeout_seconds == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = timeout_seconds;
timeout.tv_usec = 0;
}
/* TODO: how to cancel this ? */
if (want_read)
r = select(s + 1, &fds, NULL, NULL, &timeout);
@ -377,7 +383,9 @@ static int mailstream_openssl_client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **p
return 0;
}
static struct mailstream_ssl_data * ssl_data_new_full(int fd, const SSL_METHOD * method, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static struct mailstream_ssl_data * ssl_data_new_full(int fd, time_t timeout,
SSL_METHOD * method, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data),
void * cb_data)
{
struct mailstream_ssl_data * ssl_data;
SSL * ssl_conn;
@ -411,14 +419,14 @@ again:
switch(SSL_get_error(ssl_conn, r)) {
case SSL_ERROR_WANT_READ:
r = wait_SSL_connect(fd, 1);
r = wait_SSL_connect(fd, 1, timeout);
if (r < 0)
goto free_ssl_conn;
else
goto again;
break;
case SSL_ERROR_WANT_WRITE:
r = wait_SSL_connect(fd, 0);
r = wait_SSL_connect(fd, 0, timeout);
if (r < 0)
goto free_ssl_conn;
else
@ -459,14 +467,16 @@ again:
return NULL;
}
static struct mailstream_ssl_data * ssl_data_new(int fd, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static struct mailstream_ssl_data * ssl_data_new(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
{
return ssl_data_new_full(fd, SSLv23_client_method(), callback, cb_data);
return ssl_data_new_full(fd, timeout, SSLv23_client_method(), callback, cb_data);
}
static struct mailstream_ssl_data * tls_data_new(int fd, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static struct mailstream_ssl_data * tls_data_new(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
{
return ssl_data_new_full(fd, TLSv1_client_method(), callback, cb_data);
return ssl_data_new_full(fd, timeout, TLSv1_client_method(), callback, cb_data);
}
#else
@ -497,7 +507,8 @@ static int mailstream_gnutls_client_cert_cb(gnutls_session session,
return 0;
}
static struct mailstream_ssl_data * ssl_data_new(int fd, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static struct mailstream_ssl_data * ssl_data_new(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
{
struct mailstream_ssl_data * ssl_data;
gnutls_session session;
@ -535,6 +546,14 @@ static struct mailstream_ssl_data * ssl_data_new(int fd, void (* callback)(struc
/* lower limits on server key length restriction */
gnutls_dh_set_prime_bits(session, 512);
if (timeout == 0) {
timeout_value = mailstream_network_delay.tv_sec * 1000 + timeout.tv_usec / 1000;
}
else {
timeout_value = timeout;
}
gnutls_handshake_set_timeout(session, timeout_value);
do {
r = gnutls_handshake(session);
} while (r == GNUTLS_E_AGAIN || r == GNUTLS_E_INTERRUPTED);
@ -574,9 +593,10 @@ static struct mailstream_ssl_data * ssl_data_new(int fd, void (* callback)(struc
err:
return NULL;
}
static struct mailstream_ssl_data * tls_data_new(int fd, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static struct mailstream_ssl_data * tls_data_new(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
{
return ssl_data_new(fd, callback, cb_data);
return ssl_data_new(fd, timeout, callback, cb_data);
}
#endif
@ -623,16 +643,17 @@ static void ssl_data_close(struct mailstream_ssl_data * ssl_data)
#endif
static mailstream_low * mailstream_low_ssl_open_full(int fd, int starttls, void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
static mailstream_low * mailstream_low_ssl_open_full(int fd, int starttls, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * cb_data), void * cb_data)
{
#ifdef USE_SSL
mailstream_low * s;
struct mailstream_ssl_data * ssl_data;
if (starttls)
ssl_data = tls_data_new(fd, callback, cb_data);
ssl_data = tls_data_new(fd, timeout, callback, cb_data);
else
ssl_data = ssl_data_new(fd, callback, cb_data);
ssl_data = ssl_data_new(fd, timeout, callback, cb_data);
if (ssl_data == NULL)
goto err;
@ -640,6 +661,7 @@ static mailstream_low * mailstream_low_ssl_open_full(int fd, int starttls, void
s = mailstream_low_new(ssl_data, mailstream_ssl_driver);
if (s == NULL)
goto free_ssl_data;
mailstream_low_set_timeout(s, timeout);
return s;
@ -654,12 +676,22 @@ static mailstream_low * mailstream_low_ssl_open_full(int fd, int starttls, void
mailstream_low * mailstream_low_ssl_open(int fd)
{
return mailstream_low_ssl_open_full(fd, 0, NULL, NULL);
return mailstream_low_ssl_open_timeout(fd, 0);
}
mailstream_low * mailstream_low_tls_open(int fd)
{
return mailstream_low_ssl_open_full(fd, 1, NULL, NULL);
return mailstream_low_tls_open_timeout(fd, 0);
}
mailstream_low * mailstream_low_ssl_open_timeout(int fd, time_t timeout)
{
return mailstream_low_ssl_open_full(fd, 0, timeout, NULL, NULL);
}
mailstream_low * mailstream_low_tls_open_timeout(int fd, time_t timeout)
{
return mailstream_low_ssl_open_full(fd, 1, timeout, NULL, NULL);
}
#ifdef USE_SSL
@ -707,7 +739,13 @@ static int wait_read(mailstream_low * s)
#endif
ssl_data = (struct mailstream_ssl_data *) s->data;
timeout = mailstream_network_delay;
if (s->timeout == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = s->timeout;
timeout.tv_usec = 0;
}
#ifdef USE_GNUTLS
if (gnutls_record_check_pending(ssl_data->session) != 0)
@ -849,7 +887,13 @@ static int wait_write(mailstream_low * s)
if (mailstream_cancel_cancelled(ssl_data->cancel))
return -1;
timeout = mailstream_network_delay;
if (s->timeout == 0) {
timeout = mailstream_network_delay;
}
else {
timeout.tv_sec = s->timeout;
timeout.tv_usec = 0;
}
FD_ZERO(&fds_read);
fd = mailstream_cancel_get_fd(ssl_data->cancel);
@ -964,17 +1008,28 @@ static ssize_t mailstream_low_ssl_write(mailstream_low * s,
mailstream * mailstream_ssl_open(int fd)
{
return mailstream_ssl_open_with_callback(fd, NULL, NULL);
return mailstream_ssl_open_timeout(fd, 0);
}
mailstream * mailstream_ssl_open_timeout(int fd, time_t timeout)
{
return mailstream_ssl_open_with_callback_timeout(fd, timeout, NULL, NULL);
}
mailstream * mailstream_ssl_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
return mailstream_ssl_open_with_callback_timeout(fd, 0, callback, data);
}
mailstream * mailstream_ssl_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
#ifdef USE_SSL
mailstream_low * low;
mailstream * s;
low = mailstream_low_ssl_open_with_callback(fd, callback, data);
low = mailstream_low_ssl_open_with_callback_timeout(fd, timeout, callback, data);
if (low == NULL)
goto err;
@ -1072,13 +1127,25 @@ static void mailstream_low_ssl_cancel(mailstream_low * s)
mailstream_low * mailstream_low_ssl_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
return mailstream_low_ssl_open_full(fd, 0, callback, data);
return mailstream_low_ssl_open_with_callback_timeout(fd, 0, callback, data);
}
mailstream_low * mailstream_low_ssl_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
return mailstream_low_ssl_open_full(fd, 0, timeout, callback, data);
}
mailstream_low * mailstream_low_tls_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
return mailstream_low_ssl_open_full(fd, 1, callback, data);
return mailstream_low_tls_open_with_callback_timeout(fd, 0, callback, data);
}
mailstream_low * mailstream_low_tls_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
return mailstream_low_ssl_open_full(fd, 1, timeout, callback, data);
}
int mailstream_ssl_set_client_certicate(struct mailstream_ssl_context * ssl_context,

View File

@ -58,16 +58,29 @@ struct mailstream_ssl_context;
LIBETPAN_EXPORT
mailstream_low * mailstream_low_ssl_open(int fd);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_ssl_open_timeout(int fd, time_t timeout);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_tls_open(int fd);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_tls_open_timeout(int fd, time_t timeout);
LIBETPAN_EXPORT
mailstream * mailstream_ssl_open(int fd);
LIBETPAN_EXPORT
mailstream * mailstream_ssl_open_timeout(int fd, time_t timeout);
LIBETPAN_EXPORT
mailstream * mailstream_ssl_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
mailstream * mailstream_ssl_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
void mailstream_gnutls_init_not_required(void);
@ -84,10 +97,18 @@ LIBETPAN_EXPORT
mailstream_low * mailstream_low_ssl_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_ssl_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_tls_open_with_callback(int fd,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
mailstream_low * mailstream_low_tls_open_with_callback_timeout(int fd, time_t timeout,
void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data);
LIBETPAN_EXPORT
int mailstream_ssl_set_client_certicate(struct mailstream_ssl_context * ssl_context,
char * file_name);

View File

@ -85,7 +85,8 @@ struct _mailstream_low {
void * data;
mailstream_low_driver * driver;
int privacy;
char * identifier;
char * identifier;
unsigned long timeout; /* in seconds, 0 will use the global value */
};
typedef void progress_function(size_t current, size_t maximum);

View File

@ -46,6 +46,8 @@ int mailimap_idle(mailimap * session)
struct mailimap_response * response;
clist * resp_data_list;
session->imap_selection_info->sel_has_exists = 0;
session->imap_selection_info->sel_has_recent = 0;
session->imap_idle_timestamp = time(NULL);
r = mailimap_send_current_tag(session);

View File

@ -1611,16 +1611,16 @@ int mailimap_authenticate(mailimap * session, const char * auth_type,
}
sasl_callback[0].id = SASL_CB_GETREALM;
sasl_callback[0].proc = sasl_getrealm;
sasl_callback[0].proc = (int(*)(void)) sasl_getrealm;
sasl_callback[0].context = session;
sasl_callback[1].id = SASL_CB_USER;
sasl_callback[1].proc = sasl_getsimple;
sasl_callback[1].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[1].context = session;
sasl_callback[2].id = SASL_CB_AUTHNAME;
sasl_callback[2].proc = sasl_getsimple;
sasl_callback[2].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[2].context = session;
sasl_callback[3].id = SASL_CB_PASS;
sasl_callback[3].proc = sasl_getsecret;
sasl_callback[3].proc = (int(*)(void)) sasl_getsecret;
sasl_callback[3].context = session;
sasl_callback[4].id = SASL_CB_LIST_END;
sasl_callback[4].proc = NULL;
@ -2591,6 +2591,8 @@ mailimap * mailimap_new(size_t imap_progr_rate,
f->imap_msg_att_handler = NULL;
f->imap_msg_att_handler_context = NULL;
f->imap_timeout = 0;
return f;
free_stream_buffer:
@ -2627,6 +2629,18 @@ void mailimap_free(mailimap * session)
free(session);
}
LIBETPAN_EXPORT
void mailimap_set_timeout(mailimap * session, time_t timeout)
{
session->imap_timeout = timeout;
}
LIBETPAN_EXPORT
time_t mailimap_get_timeout(mailimap * session)
{
return session->imap_timeout;
}
LIBETPAN_EXPORT
void mailimap_set_progress_callback(mailimap * session,
mailprogress_function * body_progr_fun,

View File

@ -669,6 +669,12 @@ void mailimap_set_msg_att_handler(mailimap * session,
mailimap_msg_att_handler * handler,
void * context);
LIBETPAN_EXPORT
void mailimap_set_timeout(mailimap * session, time_t timeout);;
LIBETPAN_EXPORT
time_t mailimap_get_timeout(mailimap * session);
#ifdef __cplusplus
}
#endif

View File

@ -79,11 +79,11 @@ int mailimap_socket_connect_voip(mailimap * f, const char * server, uint16_t por
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->imap_timeout);
if (s == -1)
return MAILIMAP_ERROR_CONNECTION_REFUSED;
stream = mailstream_socket_open(s);
stream = mailstream_socket_open_timeout(s, f->imap_timeout);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
@ -137,7 +137,8 @@ int mailimap_socket_starttls_with_callback(mailimap * f,
if (fd == -1)
return MAILIMAP_ERROR_STREAM;
new_low = mailstream_low_tls_open_with_callback(fd, callback, data);
new_low = mailstream_low_tls_open_with_callback_timeout(fd, f->imap_timeout,
callback, data);
if (new_low == NULL)
return MAILIMAP_ERROR_STREAM;
@ -151,7 +152,7 @@ static int mailimap_cfsocket_connect_voip(mailimap * f, const char * server, uin
{
mailstream * stream;
stream = mailstream_cfstream_open_voip(server, port, voip_enabled);
stream = mailstream_cfstream_open_voip_timeout(server, port, voip_enabled, f->imap_timeout);
if (stream == NULL) {
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}

View File

@ -87,11 +87,11 @@ int mailimap_ssl_connect_voip_with_callback(mailimap * f, const char * server, u
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->imap_timeout);
if (s == -1)
return MAILIMAP_ERROR_CONNECTION_REFUSED;
stream = mailstream_ssl_open_with_callback(s, callback, data);
stream = mailstream_ssl_open_with_callback_timeout(s, f->imap_timeout, callback, data);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
@ -120,7 +120,7 @@ static int mailimap_cfssl_connect_voip_ssl_level(mailimap * f, const char * serv
mailstream * stream;
int r;
stream = mailstream_cfstream_open_voip(server, port, voip_enabled);
stream = mailstream_cfstream_open_voip_timeout(server, port, voip_enabled, f->imap_timeout);
if (stream == NULL) {
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}

View File

@ -3167,6 +3167,8 @@ struct mailimap {
void * imap_progress_context;
mailimap_msg_att_handler * imap_msg_att_handler;
void * imap_msg_att_handler_context;
time_t imap_timeout;
};
typedef struct mailimap mailimap;

View File

@ -97,7 +97,7 @@ struct mailimap_msg_att_xgmlabels * mailimap_msg_att_xgmlabels_new_empty(void)
att = mailimap_msg_att_xgmlabels_new(list);
if (att == NULL) {
clist_free(att->att_labels);
clist_free(list);
free(att);
return NULL;
}

View File

@ -105,6 +105,8 @@ newsnntp * newsnntp_new(size_t progr_rate, progress_function * progr_fun)
if (f->nntp_response_buffer == NULL)
goto free_stream_buffer;
f->nntp_timeout = 0;
return f;
free_stream_buffer:
@ -127,15 +129,15 @@ void newsnntp_free(newsnntp * f)
}
void newsnntp_set_timeout(newsnntp * f, time_t timeout)
{
f->nntp_timeout = timeout;
}
time_t newsnntp_get_timeout(newsnntp * f)
{
return f->nntp_timeout;
}

View File

@ -58,6 +58,9 @@ newsnntp * newsnntp_new(size_t nntp_progr_rate,
progress_function * nntp_progr_fun);
void newsnntp_free(newsnntp * f);
void newsnntp_set_timeout(newsnntp * f, time_t timeout);
time_t newsnntp_get_timeout(newsnntp * f);
int newsnntp_quit(newsnntp * f);
int newsnntp_connect(newsnntp * f, mailstream * s);

View File

@ -76,17 +76,18 @@ int newsnntp_socket_connect(newsnntp * f, const char * server, uint16_t port)
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->nntp_timeout);
if (s == -1)
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
stream = mailstream_socket_open(s);
stream = mailstream_socket_open_timeout(s, f->nntp_timeout);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
#else
close(s);
#endif
return NEWSNNTP_ERROR_MEMORY;
}
@ -97,7 +98,7 @@ static int newsnntp_cfsocket_connect(newsnntp * f, const char * server, uint16_t
{
mailstream * stream;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, f->nntp_timeout);
if (stream == NULL) {
return NEWSNNTP_ERROR_STREAM;
}

View File

@ -84,11 +84,11 @@ int newsnntp_ssl_connect_with_callback(newsnntp * f, const char * server, uint16
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->nntp_timeout);
if (s == -1)
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
stream = mailstream_ssl_open_with_callback(s, callback, data);
stream = mailstream_ssl_open_with_callback_timeout(s, f->nntp_timeout, callback, data);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
@ -106,7 +106,7 @@ static int newsnntp_cfssl_connect_ssl_level(newsnntp * f, const char * server, u
mailstream * stream;
int r;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, f->nntp_timeout);
if (stream == NULL) {
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
}

View File

@ -88,6 +88,8 @@ struct newsnntp
MMAPString * nntp_response_buffer;
char * nntp_response;
time_t nntp_timeout;
};
typedef struct newsnntp newsnntp;

View File

@ -1394,16 +1394,16 @@ int mailpop3_auth(mailpop3 * f, const char * auth_type,
unsigned int max_encoded;
sasl_callback[0].id = SASL_CB_GETREALM;
sasl_callback[0].proc = sasl_getrealm;
sasl_callback[0].proc = (int(*)(void)) sasl_getrealm;
sasl_callback[0].context = f;
sasl_callback[1].id = SASL_CB_USER;
sasl_callback[1].proc = sasl_getsimple;
sasl_callback[1].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[1].context = f;
sasl_callback[2].id = SASL_CB_AUTHNAME;
sasl_callback[2].proc = sasl_getsimple;
sasl_callback[2].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[2].context = f;
sasl_callback[3].id = SASL_CB_PASS;
sasl_callback[3].proc = sasl_getsecret;
sasl_callback[3].proc = (int(*)(void)) sasl_getsecret;
sasl_callback[3].context = f;
sasl_callback[4].id = SASL_CB_LIST_END;
sasl_callback[4].proc = NULL;
@ -1569,3 +1569,13 @@ int mailpop3_auth(mailpop3 * f, const char * auth_type,
return MAILPOP3_ERROR_BAD_USER;
#endif
}
void mailpop3_set_timeout(mailpop3 * f, time_t timeout)
{
f->pop3_timeout = timeout;
}
time_t mailpop3_get_timeout(mailpop3 * f)
{
return f->pop3_timeout;
}

View File

@ -57,6 +57,14 @@ mailpop3 * mailpop3_new(size_t pop3_progr_rate,
LIBETPAN_EXPORT
void mailpop3_free(mailpop3 * f);
LIBETPAN_EXPORT
void mailpop3_set_timeout(mailpop3 * f, time_t timeout);
LIBETPAN_EXPORT
time_t mailpop3_get_timeout(mailpop3 * f);
LIBETPAN_EXPORT
LIBETPAN_EXPORT
int mailpop3_connect(mailpop3 * f, mailstream * s);

View File

@ -76,11 +76,11 @@ int mailpop3_socket_connect(mailpop3 * f, const char * server, uint16_t port)
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->pop3_timeout);
if (s == -1)
return MAILPOP3_ERROR_CONNECTION_REFUSED;
stream = mailstream_socket_open(s);
stream = mailstream_socket_open_timeout(s, f->pop3_timeout);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
@ -129,8 +129,8 @@ int mailpop3_socket_starttls_with_callback(mailpop3 * f,
if (fd == -1)
return MAILPOP3_ERROR_STREAM;
new_low = mailstream_low_tls_open_with_callback(fd,
callback, data);
new_low = mailstream_low_tls_open_with_callback_timeout(fd,
f->pop3_timeout, callback, data);
if (new_low == NULL)
return MAILPOP3_ERROR_SSL;
@ -144,7 +144,7 @@ static int mailpop3_cfsocket_connect(mailpop3 * f, const char * server, uint16_t
{
mailstream * stream;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, f->pop3_timeout);
if (stream == NULL) {
return MAILPOP3_ERROR_CONNECTION_REFUSED;
}

View File

@ -85,11 +85,11 @@ int mailpop3_ssl_connect_with_callback(mailpop3 * f, const char * server, uint16
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, f->pop3_timeout);
if (s == -1)
return MAILPOP3_ERROR_CONNECTION_REFUSED;
stream = mailstream_ssl_open_with_callback(s, callback, data);
stream = mailstream_ssl_open_with_callback_timeout(s, f->pop3_timeout, callback, data);
if (stream == NULL) {
#ifdef WIN32
closesocket(s);
@ -107,7 +107,7 @@ static int mailpop3_cfssl_connect_ssl_level(mailpop3 * f, const char * server, u
mailstream * stream;
int r;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, f->pop3_timeout);
if (stream == NULL) {
return MAILPOP3_ERROR_CONNECTION_REFUSED;
}

View File

@ -93,6 +93,8 @@ struct mailpop3
const char * sasl_realm;
void * sasl_secret;
} pop3_sasl;
time_t pop3_timeout;
};
typedef struct mailpop3 mailpop3;

View File

@ -951,7 +951,8 @@ int mailsmtp_auth(mailsmtp * session, const char * user, const char * pass)
/* TODO: add mailesmtp_etrn, mailssmtp_expn */
int mailesmtp_starttls(mailsmtp * session) {
int mailesmtp_starttls(mailsmtp * session)
{
int r;
if (!(session->esmtp & MAILSMTP_ESMTP_STARTTLS))
@ -1203,16 +1204,16 @@ int mailesmtp_auth_sasl(mailsmtp * session, const char * auth_type,
unsigned int max_encoded;
sasl_callback[0].id = SASL_CB_GETREALM;
sasl_callback[0].proc = sasl_getrealm;
sasl_callback[0].proc = (int(*)(void)) sasl_getrealm;
sasl_callback[0].context = session;
sasl_callback[1].id = SASL_CB_USER;
sasl_callback[1].proc = sasl_getsimple;
sasl_callback[1].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[1].context = session;
sasl_callback[2].id = SASL_CB_AUTHNAME;
sasl_callback[2].proc = sasl_getsimple;
sasl_callback[2].proc = (int(*)(void)) sasl_getsimple;
sasl_callback[2].context = session;
sasl_callback[3].id = SASL_CB_PASS;
sasl_callback[3].proc = sasl_getsecret;
sasl_callback[3].proc = (int(*)(void)) sasl_getsecret;
sasl_callback[3].context = session;
sasl_callback[4].id = SASL_CB_LIST_END;
sasl_callback[4].proc = NULL;
@ -1438,3 +1439,14 @@ void mailsmtp_set_progress_callback(mailsmtp * session,
session->smtp_progress_fun = progr_fun;
session->smtp_progress_context = context;
}
void mailsmtp_set_timeout(mailsmtp * session, time_t timeout)
{
session->smtp_timeout = timeout;
}
time_t mailsmtp_get_timeout(mailsmtp * session)
{
return session->smtp_timeout;
}

View File

@ -54,6 +54,12 @@ mailsmtp * mailsmtp_new(size_t progr_rate,
LIBETPAN_EXPORT
void mailsmtp_free(mailsmtp * session);
LIBETPAN_EXPORT
void mailsmtp_set_timeout(mailsmtp * session, time_t timeout);
LIBETPAN_EXPORT
time_t mailsmtp_get_timeout(mailsmtp * session);
LIBETPAN_EXPORT
int mailsmtp_connect(mailsmtp * session, mailstream * s);

View File

@ -79,7 +79,7 @@ int mailsmtp_socket_connect(mailsmtp * session,
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, session->smtp_timeout);
if (s == -1)
return MAILSMTP_ERROR_CONNECTION_REFUSED;
@ -125,7 +125,7 @@ int mailsmtp_socket_starttls_with_callback(mailsmtp * session,
if (fd == -1)
return MAILSMTP_ERROR_STREAM;
new_low = mailstream_low_tls_open_with_callback(fd, callback, data);
new_low = mailstream_low_tls_open_with_callback_timeout(fd, session->smtp_timeout, callback, data);
if (new_low == NULL)
return MAILSMTP_ERROR_SSL;
@ -140,7 +140,7 @@ static int mailsmtp_cfsocket_connect(mailsmtp * session,
{
mailstream * stream;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, session->smtp_timeout);
if (stream == NULL) {
return MAILSMTP_ERROR_CONNECTION_REFUSED;
}

View File

@ -89,11 +89,11 @@ int mailsmtp_ssl_connect_with_callback(mailsmtp * session,
/* Connection */
s = mail_tcp_connect(server, port);
s = mail_tcp_connect_timeout(server, port, session->smtp_timeout);
if (s == -1)
return MAILSMTP_ERROR_CONNECTION_REFUSED;
stream = mailstream_ssl_open_with_callback(s, callback, data);
stream = mailstream_ssl_open_with_callback_timeout(s, session->smtp_timeout, callback, data);
if (stream == NULL) {
close(s);
return MAILSMTP_ERROR_SSL;
@ -108,7 +108,7 @@ static int mailsmtp_cfssl_connect_ssl_level(mailsmtp * session,
mailstream * stream;
int r;
stream = mailstream_cfstream_open(server, port);
stream = mailstream_cfstream_open_timeout(server, port, session->smtp_timeout);
if (stream == NULL) {
return MAILSMTP_ERROR_CONNECTION_REFUSED;
}

View File

@ -129,6 +129,8 @@ struct mailsmtp {
void * smtp_progress_context;
int response_code;
time_t smtp_timeout;
};
typedef struct mailsmtp mailsmtp;