[PATCH 8/9] shared/hfp_at: Add function to get string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It will look for quoted sting and write it to buffer.
---
 src/shared/hfp_at.c | 32 ++++++++++++++++++++++++++++++++
 src/shared/hfp_at.h |  2 ++
 2 files changed, 34 insertions(+)

diff --git a/src/shared/hfp_at.c b/src/shared/hfp_at.c
index 2db40b2..750133f 100644
--- a/src/shared/hfp_at.c
+++ b/src/shared/hfp_at.c
@@ -246,6 +246,38 @@ bool hfp_at_get_number(struct hfp_at *hfp_at, const char *data, int *val)
 	return true;
 }
 
+bool hfp_at_get_string(struct hfp_at *hfp_at, const char *data, char *buf,
+								uint8_t len)
+{
+	int i = 0;
+
+	hfp_at_skip_whitespace(hfp_at, data);
+
+	if (data[hfp_at->offset] != '"')
+		return false;
+
+	hfp_at->offset++;
+
+	while (data[hfp_at->offset] != '\0' && data[hfp_at->offset] != '"') {
+		if (i < len)
+			buf[i++] = data[hfp_at->offset];
+		hfp_at->offset++;
+	}
+
+	if (i < len)
+		buf[i++] = '\0';
+
+	if (data[hfp_at->offset] == '"')
+		hfp_at->offset++;
+	else
+		return false;
+
+	hfp_at_skip_whitespace(hfp_at, data);
+	hfp_at_next_field(hfp_at, data);
+
+	return true;
+}
+
 bool hfp_at_open_container(struct hfp_at *hfp_at, const char *data)
 {
 	hfp_at_skip_whitespace(hfp_at, data);
diff --git a/src/shared/hfp_at.h b/src/shared/hfp_at.h
index e709acb..4da381b 100644
--- a/src/shared/hfp_at.h
+++ b/src/shared/hfp_at.h
@@ -45,6 +45,8 @@ bool hfp_at_process_data(struct hfp_at *hfp_at, const char *data,
 bool hfp_at_get_number(struct hfp_at *hfp_at, const char *data, int *val);
 bool hfp_at_open_container(struct hfp_at *hfp_at, const char *data);
 bool hfp_at_close_container(struct hfp_at *hfp_at, const char *data);
+bool hfp_at_get_string(struct hfp_at *hfp_at, const char *data, char *buf,
+								uint8_t len);
 
 struct hfp_at *hfp_at_new(const struct hfp_at_handler *handlers);
 void hfp_at_free(struct hfp_at *hfp_at);
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux