[PATCH 03/11] Add basic command parsing

Zhenhua Zhang zhenhua.zhang at intel.com
Wed Mar 17 07:30:33 PDT 2010


According to V.250 5.3.1, the basic command is either a single
character or the '&' followed by a single character.
---
 gatchat/gatserver.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 67 insertions(+), 1 deletions(-)

diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index fb82ad4..b68894d 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -211,10 +211,67 @@ static char *parse_extended_command(GAtServer *server, const char *buf,
 	return NULL;
 }
 
+static gboolean get_basic_prefix(const char *buf, char *prefix)
+{
+	char c = *buf;
+
+	if (g_ascii_isalpha(c)) {
+		c = g_ascii_toupper(c);
+		if (c == 'S') {
+			int i = 0;
+
+			prefix[0] = 'S';
+
+			/* V.250 5.3.2 'S' command follows with
+			 * a parameter number.
+			 */
+			while (g_ascii_isdigit(buf[++i]))
+				prefix[i] = buf[i];
+
+			prefix[i] = '\0';
+		} else {
+			prefix[0] = c;
+			prefix[1] = '\0';
+		}
+	} else if (c == '&') {
+		prefix[0] = '&';
+		prefix[1] = g_ascii_toupper(buf[1]);
+		prefix[2] = '\0';
+	} else
+		return FALSE;
+
+	return TRUE;
+}
+
 static char *parse_basic_command(GAtServer *server, const char *buf,
 					char *prefix)
 {
-	return NULL;
+	char t = server->v250.s3;
+	int i;
+
+	if (!get_basic_prefix(buf, prefix))
+		return NULL;
+
+	i = strlen(prefix);
+
+	if (*buf == 'D' || *buf == 'd') {
+		/* All following characters are the part of the call */
+		while (buf[i] && buf[i] != t)
+			i++;
+	} else {
+		/* Skip '=', '?' if have */
+		if (buf[i] == '=')
+			i++;
+
+		if (buf[i] == '?')
+			i++;
+
+		/* V.250 5.3.1 The subparameter are all digits if have */
+		while (g_ascii_isdigit(buf[i]))
+			i++;
+	}
+
+	return g_strndup(buf, i);
 }
 
 static char *parse_next_command(GAtServer *server, const char *buf,
@@ -263,6 +320,15 @@ static void server_parse_line(GAtServer *server, char *line)
 			break;
 		}
 
+		/* Commands like ATA, ATD, ATZ cause the remainder line
+		 * to be ignored.
+		 */
+		if (!strcmp(prefix, "A") || !strcmp(prefix, "D") ||
+				!strcmp(prefix, "Z")) {
+			g_free(command);
+			break;
+		}
+
 		buf += strlen(command);
 
 		g_free(command);
-- 
1.6.6.1



More information about the ofono mailing list