1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-11 20:15:03 -05:00

imap: Added a helper function for upcoming untagged response filtering

RFC 3501 states that "the client MUST be prepared to accept any response
at all times" yet we assume anything received with "* " at the beginning
is the untagged response we want.

Introduced a helper function that checks whether the input looks like a
response to specified command, so that we may filter the ones we are
interested in according to the current state.
This commit is contained in:
Jiri Hruska 2013-02-26 18:52:19 +01:00 committed by Steve Holme
parent 1ffdc5058e
commit 91b2184e1b

View File

@ -323,6 +323,41 @@ static char* imap_atom(const char* str)
return newstr; return newstr;
} }
/* Determines whether the untagged response is related to a specified
command by checking if it is in format "* <command-name> ..." or
"* <number> <command-name> ...". The "* " marker is assumed to have
already been checked by the caller. */
static bool imap_matchresp(const char *line, size_t len, const char *cmd)
{
const char *end = line + len;
size_t cmd_len = strlen(cmd);
/* Skip the untagged response marker */
line += 2;
/* Do we have a number after the marker? */
if(line < end && ISDIGIT(*line)) {
/* Skip the number */
do
line++;
while(line < end && ISDIGIT(*line));
/* Do we have the space character? */
if(line == end || *line != ' ')
return FALSE;
line++;
}
/* Does the command name match and is it followed by a space character or at
the end of line? */
if(line + cmd_len <= end && Curl_raw_nequal(line, cmd, cmd_len) &&
(line[cmd_len] == ' ' || line + cmd_len == end))
return TRUE;
return FALSE;
}
/* Function that checks whether the given string is a valid tagged, untagged /* Function that checks whether the given string is a valid tagged, untagged
or continuation response which can be processed by the response handler. */ or continuation response which can be processed by the response handler. */
static bool imap_endofresp(struct connectdata *conn, char *line, size_t len, static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,