diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-02-01 17:58:48 -0600 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-02-01 17:59:29 -0600 |
commit | 321bb02ee3a4051f87cecac272e29d2e891b42a9 (patch) | |
tree | a3caee72d7948d8b314e578cd727a3a426f1b49d | |
parent | 57d62a0b4200b4d9a13b5e002c0b2bb665591eaa (diff) | |
download | ofono-321bb02ee3a4051f87cecac272e29d2e891b42a9.tar.bz2 |
Fix: Skip whitespace in AT command line
-rw-r--r-- | gatchat/gatserver.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c index a1f23983..7d6ed74b 100644 --- a/gatchat/gatserver.c +++ b/gatchat/gatserver.c @@ -272,14 +272,21 @@ static char *extract_line(GAtServer *p) unsigned char *buf = ring_buffer_read_ptr(p->buf, pos); int strip_front = 0; int line_length = 0; + gboolean in_string = FALSE; char *line; + int i; while (pos < p->read_so_far) { - if (line_length == 0 && (*buf == ' ' || *buf == '\t')) + if (*buf == '"') + in_string = !in_string; + + if (in_string == FALSE && (*buf == ' ' || *buf == '\t')) { + if (line_length == 0) strip_front += 1; - else + } else line_length += 1; +next: buf += 1; pos += 1; @@ -299,11 +306,32 @@ static char *extract_line(GAtServer *p) /* Strip leading whitespace + AT */ ring_buffer_drain(p->buf, strip_front + 2); - ring_buffer_read(p->buf, line, line_length); + + pos = 0; + i = 0; + wrap = ring_buffer_len_no_wrap(p->buf); + buf = ring_buffer_read_ptr(p->buf, pos); + + while (pos < (p->read_so_far - strip_front - 2)) { + if (*buf == '"') + in_string = !in_string; + + if ((*buf == ' ' || *buf == '\t') && in_string == FALSE) + ; /* Skip */ + else if (*buf != '\r') + line[i++] = *buf; + + buf += 1; + pos += 1; + + if (pos == wrap) + buf = ring_buffer_read_ptr(p->buf, pos); + } + /* Strip \r */ - ring_buffer_drain(p->buf, 1); + ring_buffer_drain(p->buf, p->read_so_far - strip_front - 2); - line[line_length] = '\0'; + line[i] = '\0'; return line; } |