Browse Source

move greeting response handling into get_cmd_result()

the primary purpose of this is getting rid of the "free-standing"
buffer_gets() call.
wip/maildir-uid-dupes-test
Oswald Buddenhagen 14 years ago
parent
commit
d1ee94f02c
  1. 54
      src/drv_imap.c

54
src/drv_imap.c

@ -129,7 +129,7 @@ typedef struct imap_store {
#endif #endif
/* Used during sequential operations like connect */ /* Used during sequential operations like connect */
int preauth; enum { GreetingPending = 0, GreetingBad, GreetingOk, GreetingPreauth } greeting;
union { union {
void (*imap_open)( store_t *srv, void *aux ); void (*imap_open)( store_t *srv, void *aux );
} callbacks; } callbacks;
@ -1098,6 +1098,7 @@ struct imap_cmd_trycreate {
struct imap_cmd *orig_cmd; struct imap_cmd *orig_cmd;
}; };
static void imap_open_store_greeted( imap_store_t * );
static void get_cmd_result_p2( imap_store_t *, struct imap_cmd *, int ); static void get_cmd_result_p2( imap_store_t *, struct imap_cmd *, int );
static int static int
@ -1105,8 +1106,9 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
{ {
struct imap_cmd *cmdp, **pcmdp; struct imap_cmd *cmdp, **pcmdp;
char *cmd, *arg, *arg1, *p; char *cmd, *arg, *arg1, *p;
int n, resp, resp2, tag; int n, resp, resp2, tag, greeted;
greeted = ctx->greeting;
for (;;) { for (;;) {
if (buffer_gets( &ctx->buf, &cmd )) if (buffer_gets( &ctx->buf, &cmd ))
break; break;
@ -1123,8 +1125,14 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
ctx->ns_personal = parse_list( &cmd ); ctx->ns_personal = parse_list( &cmd );
ctx->ns_other = parse_list( &cmd ); ctx->ns_other = parse_list( &cmd );
ctx->ns_shared = parse_list( &cmd ); ctx->ns_shared = parse_list( &cmd );
} else if (!strcmp( "OK", arg ) || !strcmp( "BAD", arg ) || } else if (ctx->greeting == GreetingPending && !strcmp( "PREAUTH", arg )) {
!strcmp( "NO", arg ) || !strcmp( "BYE", arg )) { ctx->greeting = GreetingPreauth;
parse_response_code( ctx, 0, cmd );
} else if (!strcmp( "OK", arg )) {
ctx->greeting = GreetingOk;
parse_response_code( ctx, 0, cmd );
} else if (!strcmp( "BAD", arg ) || !strcmp( "NO", arg ) || !strcmp( "BYE", arg )) {
ctx->greeting = GreetingBad;
parse_response_code( ctx, 0, cmd ); parse_response_code( ctx, 0, cmd );
} else if (!strcmp( "CAPABILITY", arg )) } else if (!strcmp( "CAPABILITY", arg ))
parse_capability( ctx, cmd ); parse_capability( ctx, cmd );
@ -1145,6 +1153,11 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd )
error( "IMAP error: unrecognized untagged response '%s'\n", arg ); error( "IMAP error: unrecognized untagged response '%s'\n", arg );
break; /* this may mean anything, so prefer not to spam the log */ break; /* this may mean anything, so prefer not to spam the log */
} }
if (greeted == GreetingPending) {
imap_ref( ctx );
imap_open_store_greeted( ctx );
return imap_deref( ctx ) ? RESP_CANCEL : RESP_OK;
}
} else if (!ctx->in_progress) { } else if (!ctx->in_progress) {
error( "IMAP error: unexpected reply: %s %s\n", arg, cmd ? cmd : "" ); error( "IMAP error: unexpected reply: %s %s\n", arg, cmd ? cmd : "" );
break; /* this may mean anything, so prefer not to spam the log */ break; /* this may mean anything, so prefer not to spam the log */
@ -1482,7 +1495,6 @@ imap_open_store( store_conf_t *conf,
imap_server_conf_t *srvc = cfg->server; imap_server_conf_t *srvc = cfg->server;
imap_store_t *ctx; imap_store_t *ctx;
store_t **ctxp; store_t **ctxp;
char *arg, *rsp;
struct hostent *he; struct hostent *he;
struct sockaddr_in addr; struct sockaddr_in addr;
int s, a[2]; int s, a[2];
@ -1579,30 +1591,26 @@ imap_open_store( store_conf_t *conf,
} }
} }
#endif #endif
get_cmd_result( ctx, 0 );
return;
/* read the greeting string */ bail:
if (buffer_gets( &ctx->buf, &rsp )) imap_open_store_bail( ctx );
goto bail; }
arg = next_arg( &rsp );
if (!arg || *arg != '*' || (arg = next_arg( &rsp )) == NULL) { static void
error( "IMAP error: invalid greeting response\n" ); imap_open_store_greeted( imap_store_t *ctx )
goto bail; {
} if (ctx->greeting == GreetingBad) {
if (!strcmp( "PREAUTH", arg ))
ctx->preauth = 1;
else if (strcmp( "OK", arg ) != 0) {
error( "IMAP error: unknown greeting response\n" ); error( "IMAP error: unknown greeting response\n" );
goto bail; imap_open_store_bail( ctx );
return;
} }
parse_response_code( ctx, 0, rsp );
if (!ctx->caps) if (!ctx->caps)
imap_exec( ctx, 0, imap_open_store_p2, "CAPABILITY" ); imap_exec( ctx, 0, imap_open_store_p2, "CAPABILITY" );
else else
imap_open_store_authenticate( ctx ); imap_open_store_authenticate( ctx );
return;
bail:
imap_open_store_bail( ctx );
} }
static void static void
@ -1617,7 +1625,7 @@ imap_open_store_p2( imap_store_t *ctx, struct imap_cmd *cmd ATTR_UNUSED, int res
static void static void
imap_open_store_authenticate( imap_store_t *ctx ) imap_open_store_authenticate( imap_store_t *ctx )
{ {
if (!ctx->preauth) { if (ctx->greeting != GreetingPreauth) {
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
imap_store_conf_t *cfg = (imap_store_conf_t *)ctx->gen.conf; imap_store_conf_t *cfg = (imap_store_conf_t *)ctx->gen.conf;
imap_server_conf_t *srvc = cfg->server; imap_server_conf_t *srvc = cfg->server;

Loading…
Cancel
Save