From bf247602fce232ab305a5f38bb402bd56c8d4efc Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Sat, 10 Dec 2005 07:01:36 +0000 Subject: [PATCH] Move IMAP response buffer out of command into IMAP_DATA. Ironically this is to prepare for pipelined commands. --- imap/auth_anon.c | 2 +- imap/auth_cram.c | 4 ++-- imap/auth_gss.c | 6 +++--- imap/auth_sasl.c | 4 ++-- imap/browse.c | 10 +++++----- imap/command.c | 34 +++++++++++++++++----------------- imap/imap.c | 30 +++++++++++++++--------------- imap/imap_private.h | 4 ++-- imap/message.c | 28 ++++++++++++++-------------- imap/util.c | 2 +- 10 files changed, 62 insertions(+), 62 deletions(-) diff --git a/imap/auth_anon.c b/imap/auth_anon.c index 6cf381a9..4152ad30 100644 --- a/imap/auth_anon.c +++ b/imap/auth_anon.c @@ -66,7 +66,7 @@ imap_auth_res_t imap_auth_anon (IMAP_DATA* idata, const char* method) goto bail; } - if (imap_code (idata->cmd.buf)) + if (imap_code (idata->buf)) return IMAP_AUTH_SUCCESS; bail: diff --git a/imap/auth_cram.c b/imap/auth_cram.c index 6206c048..a8741f39 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -71,7 +71,7 @@ imap_auth_res_t imap_auth_cram_md5 (IMAP_DATA* idata, const char* method) goto bail; } - if ((len = mutt_from_base64 (obuf, idata->cmd.buf + 2)) == -1) + if ((len = mutt_from_base64 (obuf, idata->buf + 2)) == -1) { dprint (1, (debugfile, "Error decoding base64 response.\n")); goto bail; @@ -121,7 +121,7 @@ imap_auth_res_t imap_auth_cram_md5 (IMAP_DATA* idata, const char* method) goto bail; } - if (imap_code (idata->cmd.buf)) + if (imap_code (idata->buf)) return IMAP_AUTH_SUCCESS; bail: diff --git a/imap/auth_gss.c b/imap/auth_gss.c index a861cb93..d7a79ada 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -140,7 +140,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const char* method) goto bail; } - request_buf.length = mutt_from_base64 (buf2, idata->cmd.buf + 2); + request_buf.length = mutt_from_base64 (buf2, idata->buf + 2); request_buf.value = buf2; sec_token = &request_buf; @@ -175,7 +175,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const char* method) dprint (1, (debugfile, "Error receiving server response.\n")); goto bail; } - request_buf.length = mutt_from_base64 (buf2, idata->cmd.buf + 2); + request_buf.length = mutt_from_base64 (buf2, idata->buf + 2); request_buf.value = buf2; maj_stat = gss_unwrap (&min_stat, context, &request_buf, &send_token, @@ -239,7 +239,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA* idata, const char* method) dprint (1, (debugfile, "Unexpected server continuation request.\n")); goto err_abort_cmd; } - if (imap_code (idata->cmd.buf)) + if (imap_code (idata->buf)) { /* flush the security context */ dprint (2, (debugfile, "Releasing GSS credentials\n")); diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index f33ec0a5..0ed4c32a 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -119,7 +119,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata, const char* method) if (irc == IMAP_CMD_RESPOND) { - if (sasl_decode64 (idata->cmd.buf+2, strlen (idata->cmd.buf+2), buf, LONG_STRING-1, &len) != SASL_OK) + if (sasl_decode64 (idata->buf+2, strlen (idata->buf+2), buf, LONG_STRING-1, &len) != SASL_OK) { dprint (1, (debugfile, "imap_auth_sasl: error base64-decoding server response.\n")); goto bail; @@ -175,7 +175,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA* idata, const char* method) if (rc != SASL_OK) goto bail; - if (imap_code (idata->cmd.buf)) + if (imap_code (idata->buf)) { mutt_sasl_setup_conn (idata->conn, saslconn); return IMAP_AUTH_SUCCESS; diff --git a/imap/browse.c b/imap/browse.c index b70dd385..4a914f19 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -131,7 +131,7 @@ int imap_browse (char* path, struct browser_state* state) } } } - while (ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN)); + while (ascii_strncmp (idata->buf, idata->cmd.seq, SEQLEN)); } /* if we're descending a folder, mark it as current in browser_state */ @@ -342,7 +342,7 @@ int imap_mailbox_rename(const char* mailbox) } if (imap_rename_mailbox (idata, &mx, newname) < 0) { - mutt_error (_("Rename failed: %s"), imap_get_qualifier (idata->cmd.buf)); + mutt_error (_("Rename failed: %s"), imap_get_qualifier (idata->buf)); mutt_sleep (1); goto fail; } @@ -395,7 +395,7 @@ static int browse_add_list_result (IMAP_DATA* idata, const char* cmd, isparent); } } - while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); + while ((ascii_strncmp (idata->buf, idata->cmd.seq, SEQLEN) != 0)); FREE (&mx.mbox); return 0; @@ -491,7 +491,7 @@ static int browse_get_namespace (IMAP_DATA* idata, char* nsbuf, int nsblen, if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->buf); if (ascii_strncasecmp ("NAMESPACE", s, 9) == 0) { /* There are three sections to the response, User, Other, Shared, @@ -607,7 +607,7 @@ static int browse_verify_namespace (IMAP_DATA* idata, return -1; nsi->listable |= (name != NULL); } - while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); + while ((ascii_strncmp (idata->buf, idata->cmd.seq, SEQLEN) != 0)); } return 0; diff --git a/imap/command.c b/imap/command.c index 076137fe..a4741cb9 100644 --- a/imap/command.c +++ b/imap/command.c @@ -96,7 +96,7 @@ int imap_cmd_start (IMAP_DATA* idata, const char* cmd) int imap_cmd_step (IMAP_DATA* idata) { IMAP_COMMAND* cmd = &idata->cmd; - unsigned int len = 0; + size_t len = 0; int c; if (idata->status == IMAP_FATAL) @@ -109,18 +109,18 @@ int imap_cmd_step (IMAP_DATA* idata) * line */ do { - if (len == cmd->blen) + if (len == idata->blen) { - safe_realloc (&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE); - cmd->blen = cmd->blen + IMAP_CMD_BUFSIZE; + safe_realloc (&idata->buf, idata->blen + IMAP_CMD_BUFSIZE); + idata->blen = idata->blen + IMAP_CMD_BUFSIZE; dprint (3, (debugfile, "imap_cmd_step: grew buffer to %u bytes\n", - cmd->blen)); + idata->blen)); } /* back up over '\0' */ if (len) len--; - c = mutt_socket_readln (cmd->buf + len, cmd->blen - len, idata->conn); + c = mutt_socket_readln (idata->buf + len, idata->blen - len, idata->conn); if (c <= 0) { dprint (1, (debugfile, "imap_cmd_step: Error reading server response.\n")); @@ -133,32 +133,32 @@ int imap_cmd_step (IMAP_DATA* idata) /* if we've read all the way to the end of the buffer, we haven't read a * full line (mutt_socket_readln strips the \r, so we always have at least * one character free when we've read a full line) */ - while (len == cmd->blen); + while (len == idata->blen); /* don't let one large string make cmd->buf hog memory forever */ - if ((cmd->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) + if ((idata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) { - safe_realloc (&cmd->buf, IMAP_CMD_BUFSIZE); - cmd->blen = IMAP_CMD_BUFSIZE; - dprint (3, (debugfile, "imap_cmd_step: shrank buffer to %u bytes\n", cmd->blen)); + safe_realloc (&idata->buf, IMAP_CMD_BUFSIZE); + idata->blen = IMAP_CMD_BUFSIZE; + dprint (3, (debugfile, "imap_cmd_step: shrank buffer to %u bytes\n", idata->blen)); } idata->lastread = time(NULL); /* handle untagged messages. The caller still gets its shot afterwards. */ - if (!ascii_strncmp (cmd->buf, "* ", 2) && + if (!ascii_strncmp (idata->buf, "* ", 2) && cmd_handle_untagged (idata)) return IMAP_CMD_BAD; /* server demands a continuation response from us */ - if (cmd->buf[0] == '+') + if (idata->buf[0] == '+') return IMAP_CMD_RESPOND; /* tagged completion code */ - if (!ascii_strncmp (cmd->buf, cmd->seq, SEQLEN)) + if (!ascii_strncmp (idata->buf, cmd->seq, SEQLEN)) { imap_cmd_finish (idata); - return imap_code (cmd->buf) ? IMAP_CMD_OK : IMAP_CMD_NO; + return imap_code (idata->buf) ? IMAP_CMD_OK : IMAP_CMD_NO; } return IMAP_CMD_CONTINUE; @@ -221,7 +221,7 @@ int imap_exec (IMAP_DATA* idata, const char* cmd, int flags) if (flags & IMAP_CMD_FAIL_OK) return -2; - dprint (1, (debugfile, "imap_exec: command failed: %s\n", idata->cmd.buf)); + dprint (1, (debugfile, "imap_exec: command failed: %s\n", idata->buf)); return -1; } @@ -313,7 +313,7 @@ static int cmd_handle_untagged (IMAP_DATA* idata) char* pn; int count; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->buf); if ((idata->state == IMAP_SELECTED) && isdigit ((unsigned char) *s)) { diff --git a/imap/imap.c b/imap/imap.c index a458f48f..ebd69d5f 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -285,7 +285,7 @@ static int imap_get_delim (IMAP_DATA *idata) if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->buf); if (ascii_strncasecmp ("LIST", s, 4) == 0) { s = imap_next_word (s); @@ -330,7 +330,7 @@ static int imap_check_capabilities (IMAP_DATA* idata) { if (imap_exec (idata, "CAPABILITY", 0) != 0) { - imap_error ("imap_check_capabilities", idata->cmd.buf); + imap_error ("imap_check_capabilities", idata->buf); return -1; } @@ -442,7 +442,7 @@ int imap_open_connection (IMAP_DATA* idata) return -1; } - if (ascii_strncasecmp ("* OK", idata->cmd.buf, 4) == 0) + if (ascii_strncasecmp ("* OK", idata->buf, 4) == 0) { /* TODO: Parse new tagged CAPABILITY data (* OK [CAPABILITY...]) */ if (imap_check_capabilities (idata)) @@ -492,7 +492,7 @@ int imap_open_connection (IMAP_DATA* idata) } #endif } - else if (ascii_strncasecmp ("* PREAUTH", idata->cmd.buf, 9) == 0) + else if (ascii_strncasecmp ("* PREAUTH", idata->buf, 9) == 0) { idata->state = IMAP_AUTHENTICATED; if (imap_check_capabilities (idata) != 0) @@ -631,7 +631,7 @@ int imap_open_mailbox (CONTEXT* ctx) if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - pc = idata->cmd.buf + 2; + pc = idata->buf + 2; /* Obtain list of available flags here, may be overridden by a * PERMANENTFLAGS tag in the OK response */ @@ -681,7 +681,7 @@ int imap_open_mailbox (CONTEXT* ctx) if (rc == IMAP_CMD_NO) { char *s; - s = imap_next_word (idata->cmd.buf); /* skip seq */ + s = imap_next_word (idata->buf); /* skip seq */ s = imap_next_word (s); /* Skip response */ mutt_error ("%s", s); mutt_sleep (2); @@ -692,7 +692,7 @@ int imap_open_mailbox (CONTEXT* ctx) goto fail; /* check for READ-ONLY notification */ - if (!ascii_strncasecmp (imap_get_qualifier (idata->cmd.buf), "[READ-ONLY]", 11) \ + if (!ascii_strncasecmp (imap_get_qualifier (idata->buf), "[READ-ONLY]", 11) \ && !mutt_bit_isset (idata->capabilities, ACL)) { dprint (2, (debugfile, "Mailbox is read-only.\n")); @@ -820,7 +820,7 @@ void imap_logout (IMAP_DATA* idata) while (imap_cmd_step (idata) == IMAP_CMD_CONTINUE) ; - FREE(& idata->cmd.buf); + FREE(& idata->buf); FREE(& idata); } @@ -985,7 +985,7 @@ int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, err_continue && (*err_continue != M_YES)) { *err_continue = imap_continue ("imap_sync_message: STORE failed", - idata->cmd.buf); + idata->buf); if (*err_continue != M_YES) return -1; } @@ -1098,7 +1098,7 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) idata->reopen |= IMAP_EXPUNGE_EXPECTED; if (imap_exec (idata, "EXPUNGE", 0) != 0) { - imap_error (_("imap_sync_mailbox: EXPUNGE failed"), idata->cmd.buf); + imap_error (_("imap_sync_mailbox: EXPUNGE failed"), idata->buf); rc = -1; goto out; } @@ -1270,7 +1270,7 @@ int imap_mailbox_check (char* path, int new) if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->buf); if (ascii_strncasecmp ("STATUS", s, 6) == 0) { s = imap_next_word (s); @@ -1464,7 +1464,7 @@ int imap_parse_list_response(IMAP_DATA* idata, char **name, int *noselect, if (rc != IMAP_CMD_CONTINUE) return -1; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->buf); if ((ascii_strncasecmp ("LIST", s, 4) == 0) || (ascii_strncasecmp ("LSUB", s, 4) == 0)) { @@ -1507,11 +1507,11 @@ int imap_parse_list_response(IMAP_DATA* idata, char **name, int *noselect, s = imap_next_word (s); /* name */ if (s && *s == '{') /* Literal */ { - if (imap_get_literal_count(idata->cmd.buf, &bytes) < 0) + if (imap_get_literal_count(idata->buf, &bytes) < 0) return -1; if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE) return -1; - *name = idata->cmd.buf; + *name = idata->buf; } else *name = s; @@ -1718,7 +1718,7 @@ int imap_complete(char* dest, size_t dlen, char* path) { completions++; } } - while (ascii_strncmp(idata->cmd.seq, idata->cmd.buf, SEQLEN)); + while (ascii_strncmp(idata->cmd.seq, idata->buf, SEQLEN)); if (completions) { diff --git a/imap/imap_private.h b/imap/imap_private.h index 82b85668..d4369852 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -144,8 +144,6 @@ typedef struct typedef struct { char seq[SEQLEN+1]; - char* buf; - unsigned int blen; int state; } IMAP_COMMAND; @@ -169,6 +167,8 @@ typedef struct time_t lastread; /* last time we read a command for the server */ /* who knows, one day we may run multiple commands in parallel */ IMAP_COMMAND cmd; + char* buf; + size_t blen; /* The following data is all specific to the currently SELECTED mbox */ char delim; diff --git a/imap/message.c b/imap/message.c index f2e29f44..07181a71 100644 --- a/imap/message.c +++ b/imap/message.c @@ -139,7 +139,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (rc != IMAP_CMD_CONTINUE) break; - if ((mfhrc = msg_fetch_header_fetch (idata->ctx, &h, idata->cmd.buf, fp)) == -1) + if ((mfhrc = msg_fetch_header_fetch (idata->ctx, &h, idata->buf, fp)) == -1) continue; else if (mfhrc < 0) break; @@ -237,7 +237,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (rc != IMAP_CMD_CONTINUE) break; - if ((mfhrc = msg_fetch_header (idata->ctx, &h, idata->cmd.buf, fp)) == -1) + if ((mfhrc = msg_fetch_header (idata->ctx, &h, idata->buf, fp)) == -1) continue; else if (mfhrc < 0) break; @@ -384,7 +384,7 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; - pc = idata->cmd.buf; + pc = idata->buf; pc = imap_next_word (pc); pc = imap_next_word (pc); @@ -419,7 +419,7 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) /* pick up trailing line */ if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) goto bail; - pc = idata->cmd.buf; + pc = idata->buf; fetched = 1; } @@ -450,7 +450,7 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) if (rc != IMAP_CMD_OK) goto bail; - if (!fetched || !imap_code (idata->cmd.buf)) + if (!fetched || !imap_code (idata->buf)) goto bail; /* Update the header information. Previously, we only downloaded a @@ -571,9 +571,9 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) char *pc; dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->cmd.buf)); + idata->buf)); - pc = idata->cmd.buf + SEQLEN; + pc = idata->buf + SEQLEN; SKIPWS (pc); pc = imap_next_word (pc); mutt_error ("%s", pc); @@ -607,13 +607,13 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) rc = imap_cmd_step (idata); while (rc == IMAP_CMD_CONTINUE); - if (!imap_code (idata->cmd.buf)) + if (!imap_code (idata->buf)) { char *pc; dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->cmd.buf)); - pc = idata->cmd.buf + SEQLEN; + idata->buf)); + pc = idata->buf + SEQLEN; SKIPWS (pc); pc = imap_next_word (pc); mutt_error ("%s", pc); @@ -735,9 +735,9 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete) if (rc == -2) { /* bail out if command failed for reasons other than nonexistent target */ - if (ascii_strncasecmp (imap_get_qualifier (idata->cmd.buf), "[TRYCREATE]", 11)) + if (ascii_strncasecmp (imap_get_qualifier (idata->buf), "[TRYCREATE]", 11)) { - imap_error ("imap_copy_messages", idata->cmd.buf); + imap_error ("imap_copy_messages", idata->buf); goto fail; } dprint (2, (debugfile, "imap_copy_messages: server suggests TRYCREATE\n")); @@ -755,7 +755,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete) } if (rc != 0) { - imap_error ("imap_copy_messages", idata->cmd.buf); + imap_error ("imap_copy_messages", idata->buf); goto fail; } @@ -920,7 +920,7 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp) if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE) return rc; - if (msg_parse_fetch (h, idata->cmd.buf) == -1) + if (msg_parse_fetch (h, idata->buf) == -1) return rc; } diff --git a/imap/util.c b/imap/util.c index 8df1fa41..5af39731 100644 --- a/imap/util.c +++ b/imap/util.c @@ -256,7 +256,7 @@ void imap_free_idata (IMAP_DATA** idata) { FREE (&(*idata)->capstr); mutt_free_list (&(*idata)->flags); - FREE (&((*idata)->cmd.buf)); + FREE (&((*idata)->buf)); FREE (idata); } -- 2.40.0