commit 18e1aeb01d4cb44105ad309654d733a33ea2edfd Author: Oswald Buddenhagen <o...@kde.org> Date: Sun Mar 13 12:06:49 2011 +0100
move greeting response handling into get_cmd_result() the primary purpose of this is getting rid of the "free-standing" buffer_gets() call. src/drv_imap.c | 54 +++++++++++++++++++++++++---------------------- 1 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 294228f..a28e808 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -128,7 +128,7 @@ typedef struct imap_store { #endif /* Used during sequential operations like connect */ - int preauth; + enum { GreetingPending = 0, GreetingBad, GreetingOk, GreetingPreauth } greeting; union { int (*imap_open)( store_t *srv, void *aux ); } callbacks; @@ -1094,6 +1094,7 @@ struct imap_cmd_trycreate { struct imap_cmd *orig_cmd; }; +static int imap_open_store_greeted( imap_store_t * ); static int get_cmd_result_p2( imap_store_t *, struct imap_cmd *, int ); static int @@ -1101,8 +1102,9 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd ) { struct imap_cmd *cmdp, **pcmdp; char *cmd, *arg, *arg1, *p; - int n, resp, resp2, tag; + int n, resp, resp2, tag, greeted; + greeted = ctx->greeting; for (;;) { if (buffer_gets( &ctx->buf, &cmd )) break; @@ -1119,8 +1121,14 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd ) ctx->ns_personal = parse_list( &cmd ); ctx->ns_other = parse_list( &cmd ); ctx->ns_shared = parse_list( &cmd ); - } else if (!strcmp( "OK", arg ) || !strcmp( "BAD", arg ) || - !strcmp( "NO", arg ) || !strcmp( "BYE", arg )) { + } else if (ctx->greeting == GreetingPending && !strcmp( "PREAUTH", 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 ); } else if (!strcmp( "CAPABILITY", arg )) parse_capability( ctx, cmd ); @@ -1141,6 +1149,8 @@ get_cmd_result( imap_store_t *ctx, struct imap_cmd *tcmd ) error( "IMAP error: unrecognized untagged response '%s'\n", arg ); break; /* this may mean anything, so prefer not to spam the log */ } + if (greeted == GreetingPending) + return imap_open_store_greeted( ctx ); } else if (!ctx->in_progress) { error( "IMAP error: unexpected reply: %s %s\n", arg, cmd ? cmd : "" ); break; /* this may mean anything, so prefer not to spam the log */ @@ -1448,7 +1458,6 @@ imap_open_store( store_conf_t *conf, imap_server_conf_t *srvc = cfg->server; imap_store_t *ctx; store_t **ctxp; - char *arg, *rsp; struct hostent *he; struct sockaddr_in addr; int s, a[2]; @@ -1544,30 +1553,25 @@ imap_open_store( store_conf_t *conf, } } #endif + get_cmd_result( ctx, 0 ); + return; - /* read the greeting string */ - if (buffer_gets( &ctx->buf, &rsp )) - goto bail; - arg = next_arg( &rsp ); - if (!arg || *arg != '*' || (arg = next_arg( &rsp )) == NULL) { - error( "IMAP error: invalid greeting response\n" ); - goto bail; - } - if (!strcmp( "PREAUTH", arg )) - ctx->preauth = 1; - else if (strcmp( "OK", arg ) != 0) { + bail: + imap_open_store_bail( ctx ); +} + +static int +imap_open_store_greeted( imap_store_t *ctx ) +{ + if (ctx->greeting == GreetingBad) { error( "IMAP error: unknown greeting response\n" ); - goto bail; + return imap_open_store_bail( ctx ); } - parse_response_code( ctx, 0, rsp ); + if (!ctx->caps) - imap_exec( ctx, 0, imap_open_store_p2, "CAPABILITY" ); + return imap_exec( ctx, 0, imap_open_store_p2, "CAPABILITY" ); else - imap_open_store_authenticate( ctx ); - return; - - bail: - imap_open_store_bail( ctx ); + return imap_open_store_authenticate( ctx ); } static int @@ -1582,7 +1586,7 @@ imap_open_store_p2( imap_store_t *ctx, struct imap_cmd *cmd ATTR_UNUSED, int res static int imap_open_store_authenticate( imap_store_t *ctx ) { - if (!ctx->preauth) { + if (ctx->greeting != GreetingPreauth) { #ifdef HAVE_LIBSSL imap_store_conf_t *cfg = (imap_store_conf_t *)ctx->gen.conf; imap_server_conf_t *srvc = cfg->server; ------------------------------------------------------------------------------ Xperia(TM) PLAY It's a major breakthrough. An authentic gaming smartphone on the nation's most reliable network. And it wants your games. http://p.sf.net/sfu/verizon-sfdev _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel