move use_imaps out of server_conf_t

it doesn't belong there - it's a property of imap_server_conf_t.
the port setup is now done while reading the config.

this makes socket.[hc] imap-agnostic.
This commit is contained in:
Oswald Buddenhagen 2014-07-06 10:06:40 +02:00
parent 3742fc475b
commit aa4f7a7d00
3 changed files with 19 additions and 19 deletions

View File

@ -46,6 +46,7 @@ typedef struct imap_server_conf {
int max_in_progress;
#ifdef HAVE_LIBSSL
char use_ssl;
char use_imaps;
char require_ssl;
char require_cram;
#endif
@ -1531,7 +1532,7 @@ imap_open_store_connected( int ok, void *aux )
if (!ok)
imap_open_store_bail( ctx );
#ifdef HAVE_LIBSSL
else if (srvc->sconf.use_imaps)
else if (srvc->use_imaps)
socket_start_tls( &ctx->conn, imap_open_store_tlsstarted1 );
#endif
}
@ -1581,7 +1582,7 @@ imap_open_store_authenticate( imap_store_t *ctx )
if (ctx->greeting != GreetingPreauth) {
#ifdef HAVE_LIBSSL
if (!srvc->sconf.use_imaps && srvc->use_ssl) {
if (!srvc->use_imaps && srvc->use_ssl) {
/* always try to select SSL support if available */
if (CAP(STARTTLS)) {
imap_exec( ctx, 0, imap_open_store_authenticate_p2, "STARTTLS" );
@ -1600,7 +1601,7 @@ imap_open_store_authenticate( imap_store_t *ctx )
imap_open_store_authenticate2( ctx );
} else {
#ifdef HAVE_LIBSSL
if (!srvc->sconf.use_imaps && srvc->require_ssl) {
if (!srvc->use_imaps && srvc->require_ssl) {
error( "IMAP error: SSL support not available\n" );
imap_open_store_bail( ctx );
return;
@ -2272,7 +2273,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
#ifdef HAVE_LIBSSL
if (starts_with( cfg->val, -1, "imaps:", 6 )) {
cfg->val += 6;
server->sconf.use_imaps = 1;
server->use_imaps = 1;
server->sconf.use_sslv2 = 1;
server->sconf.use_sslv3 = 1;
} else
@ -2310,7 +2311,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
} else if (!strcasecmp( "RequireSSL", cfg->cmd ))
server->require_ssl = parse_bool( cfg );
else if (!strcasecmp( "UseIMAPS", cfg->cmd ))
server->sconf.use_imaps = parse_bool( cfg );
server->use_imaps = parse_bool( cfg );
else if (!strcasecmp( "UseSSLv2", cfg->cmd ))
server->sconf.use_sslv2 = parse_bool( cfg );
else if (!strcasecmp( "UseSSLv3", cfg->cmd ))
@ -2377,6 +2378,12 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep )
return 1;
}
#endif
if (!server->sconf.port)
server->sconf.port =
#ifdef HAVE_LIBSSL
server->use_imaps ? 993 :
#endif
143;
}
if (store) {
if (!store->server) {

View File

@ -312,7 +312,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
sock->callbacks.connect = cb;
/* open connection to IMAP server */
/* open connection to server */
if (conf->tunnel) {
int a[2];
@ -352,7 +352,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
hints.ai_flags = AI_ADDRCONFIG;
infon( "Resolving %s... ", conf->host );
if ((gaierr = getaddrinfo( conf->host, NULL, &hints, &sock->addrs ))) {
error( "IMAP error: Cannot resolve server '%s': %s\n", conf->host, gai_strerror( gaierr ) );
error( "Error: Cannot resolve server '%s': %s\n", conf->host, gai_strerror( gaierr ) );
socket_connect_bail( sock );
return;
}
@ -365,7 +365,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
infon( "Resolving %s... ", conf->host );
he = gethostbyname( conf->host );
if (!he) {
error( "IMAP error: Cannot resolve server '%s': %s\n", conf->host, hstrerror( h_errno ) );
error( "Error: Cannot resolve server '%s': %s\n", conf->host, hstrerror( h_errno ) );
socket_connect_bail( sock );
return;
}
@ -381,7 +381,6 @@ static void
socket_connect_one( conn_t *sock )
{
int s;
ushort port;
#ifdef HAVE_IPV6
struct addrinfo *ai;
#else
@ -400,18 +399,13 @@ socket_connect_one( conn_t *sock )
return;
}
port = sock->conf->port ? sock->conf->port :
#ifdef HAVE_LIBSSL
sock->conf->use_imaps ? 993 :
#endif
143;
#ifdef HAVE_IPV6
if (ai->ai_family == AF_INET6) {
struct sockaddr_in6 *in6 = ((struct sockaddr_in6 *)ai->ai_addr);
char sockname[64];
in6->sin6_port = htons( port );
in6->sin6_port = htons( sock->conf->port );
nfasprintf( &sock->name, "%s ([%s]:%hu)",
sock->conf->host, inet_ntop( AF_INET6, &in6->sin6_addr, sockname, sizeof(sockname) ), port );
sock->conf->host, inet_ntop( AF_INET6, &in6->sin6_addr, sockname, sizeof(sockname) ), sock->conf->port );
} else
#endif
{
@ -421,9 +415,9 @@ socket_connect_one( conn_t *sock )
in->sin_family = AF_INET;
in->sin_addr.s_addr = *((int *)*sock->curr_addr);
#endif
in->sin_port = htons( port );
in->sin_port = htons( sock->conf->port );
nfasprintf( &sock->name, "%s (%s:%hu)",
sock->conf->host, inet_ntoa( in->sin_addr ), port );
sock->conf->host, inet_ntoa( in->sin_addr ), sock->conf->port );
}
#ifdef HAVE_IPV6

View File

@ -34,7 +34,6 @@ typedef struct server_conf {
int port;
#ifdef HAVE_LIBSSL
char *cert_file;
char use_imaps;
char use_sslv2, use_sslv3, use_tlsv1, use_tlsv11, use_tlsv12;
/* these are actually variables and are leaked at the end */