Beispiel #1
0
int newsnntp_ssl_connect_with_callback(newsnntp * f, const char * server, uint16_t port,
    void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data)
{
  int s;
  mailstream * stream;

  if (port == 0) {
    port = mail_get_service_port(SERVICE_NAME_NNTPS, SERVICE_TYPE_TCP);
    if (port == 0)
      port = DEFAULT_NNTPS_PORT;
  }

  /* Connection */

  s = mail_tcp_connect(server, port);
  if (s == -1)
    return NEWSNNTP_ERROR_CONNECTION_REFUSED;

  stream = mailstream_ssl_open_with_callback(s, callback, data);
  if (stream == NULL) {
#ifdef WIN32
	closesocket(s);
#else
    close(s);
#endif
    return NEWSNNTP_ERROR_SSL;
  }

  return newsnntp_connect(f, stream);
}
Beispiel #2
0
static int newsnntp_cfsocket_connect(newsnntp * f, const char * server, uint16_t port)
{
  mailstream * stream;
  
  stream = mailstream_cfstream_open_timeout(server, port, f->nntp_timeout);
  if (stream == NULL) {
    return NEWSNNTP_ERROR_STREAM;
  }
  
  return newsnntp_connect(f, stream);
}
Beispiel #3
0
static int nntpdriver_connect_stream(mailsession * session, mailstream * s)
{
  int r;
  
  r = newsnntp_connect(get_nntp_session(session), s);

  switch (r) {
  case NEWSNNTP_NO_ERROR:
    return MAIL_NO_ERROR_NON_AUTHENTICATED;

  default:
    return nntpdriver_nntp_error_to_mail_error(r);
  }
}
Beispiel #4
0
static int newsnntp_cfssl_connect_ssl_level(newsnntp * f, const char * server, uint16_t port, int ssl_level)
{
  mailstream * stream;
  int r;

  stream = mailstream_cfstream_open(server, port);
  if (stream == NULL) {
    return NEWSNNTP_ERROR_CONNECTION_REFUSED;
  }
  mailstream_cfstream_set_ssl_level(stream, ssl_level);
  mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION);
  r = mailstream_cfstream_set_ssl_enabled(stream, 1);
  if (r < 0) {
    mailstream_close(stream);
    return NEWSNNTP_ERROR_SSL;
  }

  return newsnntp_connect(f, stream);
}
Beispiel #5
0
int newsnntp_socket_connect(newsnntp * f, const char * server, uint16_t port)
{
  int s;
  mailstream * stream;

#if HAVE_CFNETWORK
  if (mailstream_cfstream_enabled) {
    return newsnntp_cfsocket_connect(f, server, port);
  }
#endif
  
  if (port == 0) {
    port = mail_get_service_port(SERVICE_NAME_NNTP, SERVICE_TYPE_TCP);
    if (port == 0)
      port = DEFAULT_NNTP_PORT;
  }

  /* Connection */

  s = mail_tcp_connect_timeout(server, port, f->nntp_timeout);
  if (s == -1)
    return NEWSNNTP_ERROR_CONNECTION_REFUSED;

  stream = mailstream_socket_open_timeout(s, f->nntp_timeout);
  if (stream == NULL) {
#ifdef WIN32
    closesocket(s);
#else
    close(s);
#endif
		
    return NEWSNNTP_ERROR_MEMORY;
  }

  return newsnntp_connect(f, stream);
}