Diff between 9978fd058f0b735c550c3b226cbb24f189530687 and ab133e2d228ed9def82de9581552b97778b601ee

Changed Files

File Additions Deletions Status
src/shared/hfp.c +31 -0 modified
src/shared/hfp.h +2 -0 modified

Full Patch

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 945f36e..7cc9a30 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -218,6 +218,37 @@ done:
 	return true;
 }
 
+static void next_field(struct hfp_gw_result *result)
+{
+	if (result->data[result->offset] == ',')
+		result->offset++;
+}
+
+bool hfp_gw_result_get_number(struct hfp_gw_result *result, unsigned int *val)
+{
+	int tmp = 0;
+	int i;
+
+	skip_whitespace(result);
+
+	i = result->offset;
+
+	while (result->data[i] >= '0' && result->data[i] <= '9')
+		tmp = tmp * 10 + result->data[i++] - '0';
+
+	if (i == result->offset)
+		return false;
+
+	if (val)
+		*val = tmp;
+	result->offset = i;
+
+	skip_whitespace(result);
+	next_field(result);
+
+	return true;
+}
+
 static void process_input(struct hfp_gw *hfp)
 {
 	char *str, *ptr;
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index 0755a46..40adcb6 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -112,3 +112,5 @@ bool hfp_gw_register(struct hfp_gw *hfp, hfp_result_func_t callback,
 						void *user_data,
 						hfp_destroy_func_t destroy);
 bool hfp_gw_unregister(struct hfp_gw *hfp, const char *prefix);
+
+bool hfp_gw_result_get_number(struct hfp_gw_result *result, unsigned int *val);