summaryrefslogtreecommitdiff
path: root/gatchat/gatchat.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-06-08 14:06:07 -0500
committerMarcel Holtmann <marcel@holtmann.org>2009-06-09 07:39:16 +0200
commitc4c1350acbb8f5a2d0a8c288a4b6566144e85844 (patch)
tree6afa82fdd81693cab7b1fc624c2d094d0e508e03 /gatchat/gatchat.c
parent930cfd8ec8a0d0e0d4a24af709a884804799c58e (diff)
downloadconnman-c4c1350acbb8f5a2d0a8c288a4b6566144e85844.tar.gz
connman-c4c1350acbb8f5a2d0a8c288a4b6566144e85844.tar.bz2
connman-c4c1350acbb8f5a2d0a8c288a4b6566144e85844.zip
Fix multiline responses in GAtChat
The standard is a bit fuzzy on how multiline responses are returned GAtChat assumed that they will always start with <cr><lf>, however this doesn't seem to be correct. Add a new state which is entered when a response is obtained. If <cr> is encountered, then it is processed regularly, otherwise the parser assumes that the next line is part of the multiline response
Diffstat (limited to 'gatchat/gatchat.c')
-rw-r--r--gatchat/gatchat.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index e54e5d93..2492e542 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -44,6 +44,7 @@ enum chat_state {
PARSER_STATE_RESPONSE,
PARSER_STATE_TERMINATOR_CR,
PARSER_STATE_RESPONSE_COMPLETE,
+ PARSER_STATE_GUESS_MULTILINE_RESPONSE,
PARSER_STATE_PDU,
PARSER_STATE_PDU_CR,
PARSER_STATE_PDU_COMPLETE,
@@ -405,6 +406,9 @@ static gboolean g_at_chat_handle_command_response(GAtChat *p,
}
out:
+ if (!(p->flags & G_AT_CHAT_FLAG_NO_LEADING_CRLF))
+ p->state = PARSER_STATE_GUESS_MULTILINE_RESPONSE;
+
p->response_lines = g_slist_prepend(p->response_lines,
line);
@@ -554,6 +558,13 @@ static inline void parse_char(GAtChat *chat, char byte)
chat->state = PARSER_STATE_IDLE;
break;
+ case PARSER_STATE_GUESS_MULTILINE_RESPONSE:
+ if (byte == '\r')
+ chat->state = PARSER_STATE_INITIAL_CR;
+ else
+ chat->state = PARSER_STATE_RESPONSE;
+ break;
+
case PARSER_STATE_PDU:
if (byte == '\r')
chat->state = PARSER_STATE_PDU_CR;