From 91b2184e1b443ac941475ad26baabb19d1f8f493 Mon Sep 17 00:00:00 2001 From: Jiri Hruska Date: Tue, 26 Feb 2013 18:52:19 +0100 Subject: 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. --- lib/imap.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/imap.c') 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 "* ..." or + "* ...". 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, -- cgit v1.2.3