Refactor: Simplify extended command parsing logic

This commit is contained in:
Denis Kenzior 2010-03-30 14:36:02 -05:00
parent 882b62b640
commit 0448392a91
1 changed files with 6 additions and 9 deletions

View File

@ -280,7 +280,6 @@ static unsigned int parse_extended_command(GAtServer *server, char *buf)
const char *separators = ";?="; const char *separators = ";?=";
unsigned int prefix_len, i; unsigned int prefix_len, i;
gboolean in_string = FALSE; gboolean in_string = FALSE;
gboolean seen_question = FALSE;
gboolean seen_equals = FALSE; gboolean seen_equals = FALSE;
char prefix[18]; /* According to V250, 5.4.1 */ char prefix[18]; /* According to V250, 5.4.1 */
GAtServerRequestType type; GAtServerRequestType type;
@ -322,24 +321,22 @@ static unsigned int parse_extended_command(GAtServer *server, char *buf)
goto next; goto next;
if (buf[i] == '?') { if (buf[i] == '?') {
if (seen_question || seen_equals) if (seen_equals && buf[i-1] != '=')
return 0; return 0;
if (buf[i + 1] != '\0' && buf[i + 1] != ';') if (buf[i + 1] != '\0' && buf[i + 1] != ';')
return 0; return 0;
seen_question = TRUE;
type = G_AT_SERVER_REQUEST_TYPE_QUERY; type = G_AT_SERVER_REQUEST_TYPE_QUERY;
if (seen_equals)
type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
} else if (buf[i] == '=') { } else if (buf[i] == '=') {
if (seen_equals || seen_question) if (seen_equals)
return 0; return 0;
seen_equals = TRUE; seen_equals = TRUE;
type = G_AT_SERVER_REQUEST_TYPE_SET;
if (buf[i + 1] == '?')
type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
else
type = G_AT_SERVER_REQUEST_TYPE_SET;
} }
next: next: