LIBETPAN_EXPORT int mailpop3_socket_starttls_with_callback(mailpop3 * f, void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data) { int r; int fd; mailstream_low * low; mailstream_low * new_low; r = mailpop3_stls(f); switch (r) { case MAILPOP3_NO_ERROR: break; default: return r; } low = mailstream_get_low(f->pop3_stream); fd = mailstream_low_get_fd(low); if (fd == -1) return MAILPOP3_ERROR_STREAM; new_low = mailstream_low_tls_open_with_callback(fd, callback, data); if (new_low == NULL) return MAILPOP3_ERROR_SSL; mailstream_low_free(low); mailstream_set_low(f->pop3_stream, new_low); return MAILPOP3_NO_ERROR; }
int mailsmtp_socket_starttls_with_callback(mailsmtp * session, void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data) { int r; int fd; mailstream_low * low; mailstream_low * new_low; low = mailstream_get_low(session->stream); if (low->driver == mailstream_cfstream_driver) { // won't use callback return mailsmtp_cfsocket_starttls(session); } r = mailesmtp_starttls(session); if (r != MAILSMTP_NO_ERROR) return r; fd = mailstream_low_get_fd(low); if (fd == -1) return MAILSMTP_ERROR_STREAM; new_low = mailstream_low_tls_open_with_callback_timeout(fd, session->smtp_timeout, callback, data); if (new_low == NULL) return MAILSMTP_ERROR_SSL; mailstream_low_free(low); mailstream_set_low(session->stream, new_low); return MAILSMTP_NO_ERROR; }
LIBETPAN_EXPORT mailstream * mailstream_new(mailstream_low * low, size_t buffer_size) { mailstream * s; s = malloc(sizeof(* s)); if (s == NULL) goto err; s->read_buffer = malloc(buffer_size); if (s->read_buffer == NULL) goto free_s; s->read_buffer_len = 0; s->write_buffer = malloc(buffer_size); if (s->write_buffer == NULL) goto free_read_buffer; s->write_buffer_len = 0; s->buffer_max_size = buffer_size; s->low = NULL; s->idle = NULL; s->idling = 0; s->logger = NULL; s->logger_context = NULL; mailstream_set_low(s, low); return s; free_read_buffer: free(s->read_buffer); free_s: free(s); err: return NULL; }
int mailimap_socket_starttls_with_callback(mailimap * f, void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data) { mailstream_low * low; mailstream_low * new_low; int r; int fd; low = mailstream_get_low(f->imap_stream); if (low->driver == mailstream_cfstream_driver) { // won't use callback return mailimap_cfsocket_starttls(f); } r = mailimap_starttls(f); switch (r) { case MAILIMAP_NO_ERROR: break; default: return r; } fd = mailstream_low_get_fd(low); if (fd == -1) return MAILIMAP_ERROR_STREAM; new_low = mailstream_low_tls_open_with_callback_timeout(fd, f->imap_timeout, callback, data); if (new_low == NULL) return MAILIMAP_ERROR_STREAM; mailstream_low_free(low); mailstream_set_low(f->imap_stream, new_low); return MAILIMAP_NO_ERROR; }