]> code.delx.au - pulseaudio/commitdiff
core: Add a string list membership check function
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Thu, 27 Oct 2011 10:49:18 +0000 (12:49 +0200)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Fri, 28 Oct 2011 13:21:09 +0000 (15:21 +0200)
This adds a pa_str_in_list() to check for a given string in a
space-separated list of strings. For now, this is merely present to
avoid duplication of role matching code (intended roles can be a
space-separate list) across modules.

src/modules/module-filter-heuristics.c
src/modules/module-intended-roles.c
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index 5bb0945edbb37017773ebef8d54de70b26c02d34..e158b95238d1591e090ee93cecb57eab588ee8e0 100644 (file)
@@ -55,27 +55,6 @@ struct userdata {
         *source_output_move_finish_slot;
 };
 
-static pa_bool_t role_match(pa_proplist *proplist, const char *role) {
-    const char *ir;
-    char *r;
-    const char *state = NULL;
-
-    if (!(ir = pa_proplist_gets(proplist, PA_PROP_DEVICE_INTENDED_ROLES)))
-        return FALSE;
-
-    while ((r = pa_split_spaces(ir, &state))) {
-
-        if (pa_streq(role, r)) {
-            pa_xfree(r);
-            return TRUE;
-        }
-
-        pa_xfree(r);
-    }
-
-    return FALSE;
-}
-
 static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_sink_input) {
     const char *want;
     pa_proplist *pl, *parent_pl;
@@ -93,7 +72,7 @@ static pa_hook_result_t process(struct userdata *u, pa_object *o, pa_bool_t is_s
         return PA_HOOK_OK;
 
     /* On phone sinks, make sure we're not applying echo cancellation */
-    if (role_match(parent_pl, "phone")) {
+    if (pa_str_in_list_spaces(pa_proplist_gets(parent_pl, PA_PROP_DEVICE_INTENDED_ROLES), "phone")) {
         const char *apply = pa_proplist_gets(pl, PA_PROP_FILTER_APPLY);
 
         if (apply && pa_streq(apply, "echo-cancel")) {
index 9ba893b2935e8d8b6e3f3be3d386e1d20cc180fc..d1e9b818e8d26e6c8ad48305f491d32e2f419713 100644 (file)
@@ -66,24 +66,7 @@ struct userdata {
 };
 
 static pa_bool_t role_match(pa_proplist *proplist, const char *role) {
-    const char *ir;
-    char *r;
-    const char *state = NULL;
-
-    if (!(ir = pa_proplist_gets(proplist, PA_PROP_DEVICE_INTENDED_ROLES)))
-        return FALSE;
-
-    while ((r = pa_split_spaces(ir, &state))) {
-
-        if (pa_streq(role, r)) {
-            pa_xfree(r);
-            return TRUE;
-        }
-
-        pa_xfree(r);
-    }
-
-    return FALSE;
+    return pa_str_in_list_spaces(pa_proplist_gets(proplist, PA_PROP_DEVICE_INTENDED_ROLES), role);
 }
 
 static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_new_data *new_data, struct userdata *u) {
index 69986a36950e3d85e9d20a835808c2be95c24686..79c8e0820e7d902f8fcd41b8612762b69535a21f 100644 (file)
@@ -2627,6 +2627,26 @@ pa_bool_t pa_in_system_mode(void) {
     return !!atoi(e);
 }
 
+/* Checks a whitespace-separated list of words in haystack for needle */
+pa_bool_t pa_str_in_list_spaces(const char *haystack, const char *needle) {
+    char *s;
+    const char *state = NULL;
+
+    if (!haystack || !needle)
+        return FALSE;
+
+    while ((s = pa_split_spaces(haystack, &state))) {
+        if (pa_streq(needle, s)) {
+            pa_xfree(s);
+            return TRUE;
+        }
+
+        pa_xfree(s);
+    }
+
+    return FALSE;
+}
+
 char *pa_get_user_name_malloc(void) {
     ssize_t k;
     char *u;
index 2b5fe9c1657a7157b42370bf1eee3f65273fff9c..4a1c096ed3b9d41a9e1961b305f6a0042086fb20 100644 (file)
@@ -204,6 +204,7 @@ void pa_unset_env_recorded(void);
 pa_bool_t pa_in_system_mode(void);
 
 #define pa_streq(a,b) (!strcmp((a),(b)))
+pa_bool_t pa_str_in_list_spaces(const char *needle, const char *haystack);
 
 char *pa_get_host_name_malloc(void);
 char *pa_get_user_name_malloc(void);