diff options
author | Jiri Hruska <jirka@fud.cz> | 2013-02-26 18:52:19 +0100 |
---|---|---|
committer | Steve Holme <steve_holme@hotmail.com> | 2013-02-26 20:23:13 +0000 |
commit | 91b2184e1b443ac941475ad26baabb19d1f8f493 (patch) | |
tree | dcb44112ea614d79693b26d683f90f90b280ede2 /lib | |
parent | 1ffdc5058e18450f36b33dc790df9ce4265b1c6c (diff) |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/imap.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/imap.c b/lib/imap.c index 7738e63e2..68f765aeb 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -323,6 +323,41 @@ static char* imap_atom(const char* str) 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 or continuation response which can be processed by the response handler. */ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len, |