[pulseaudio-commits] 2 commits - src/map-file src/modules src/pulse src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Fri Jun 29 03:07:14 PDT 2012


 src/map-file                |    1 +
 src/modules/module-tunnel.c |   24 +++---------------------
 src/pulse/proplist.c        |   28 ++++++++++++++--------------
 src/pulse/proplist.h        |    3 +++
 src/pulsecore/tagstruct.c   |    8 +++++---
 5 files changed, 26 insertions(+), 38 deletions(-)

New commits:
commit 1edb4a470b2fb67dd5cb61fb830770ff122b4876
Author: Tanu Kaskinen <tanu.kaskinen at digia.com>
Date:   Fri Apr 13 14:40:32 2012 +0300

    tagstruct: Allow NULL proplist with pa_tagstruct_get_proplist().
    
    module-tunnel doesn't care about the proplist contents, so
    pa_tagstruct_get_proplist() is only used for removing the
    data from the tagstruct buffer. In that case it's more
    convenient to just pass NULL as the proplist argument.

diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index e336d15..4675a62 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1065,13 +1065,10 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
     pa_cvolume volume;
     pa_bool_t mute;
     pa_usec_t latency;
-    pa_proplist *pl;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1101,7 +1098,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
     if (u->version >= 13) {
         pa_usec_t configured_latency;
 
-        if (pa_tagstruct_get_proplist(t, pl) < 0 ||
+        if (pa_tagstruct_get_proplist(t, NULL) < 0 ||
             pa_tagstruct_get_usec(t, &configured_latency) < 0) {
 
             pa_log("Parse failure");
@@ -1134,8 +1131,6 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (!u->sink_name || !pa_streq(name, u->sink_name))
         return;
 
@@ -1148,7 +1143,6 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 /* Called from main context */
@@ -1161,14 +1155,11 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
     pa_cvolume volume;
-    pa_proplist *pl;
     pa_bool_t b;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1203,7 +1194,7 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
     }
 
     if (u->version >= 13) {
-        if (pa_tagstruct_get_proplist(t, pl) < 0) {
+        if (pa_tagstruct_get_proplist(t, NULL) < 0) {
 
             pa_log("Parse failure");
             goto fail;
@@ -1243,8 +1234,6 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (idx != u->device_index)
         return;
 
@@ -1263,7 +1252,6 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 #else
@@ -1278,13 +1266,10 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
     pa_cvolume volume;
     pa_bool_t mute;
     pa_usec_t latency, configured_latency;
-    pa_proplist *pl;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1312,7 +1297,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
     }
 
     if (u->version >= 13) {
-        if (pa_tagstruct_get_proplist(t, pl) < 0 ||
+        if (pa_tagstruct_get_proplist(t, NULL) < 0 ||
             pa_tagstruct_get_usec(t, &configured_latency) < 0) {
 
             pa_log("Parse failure");
@@ -1345,8 +1330,6 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (!u->source_name || !pa_streq(name, u->source_name))
         return;
 
@@ -1359,7 +1342,6 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 #endif
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index a0f1f10..762947a 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -602,7 +602,6 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
     size_t saved_rindex;
 
     pa_assert(t);
-    pa_assert(p);
 
     if (t->rindex+1 > t->length)
         return -1;
@@ -624,6 +623,9 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
         if (!k)
             break;
 
+        if (!pa_proplist_key_valid(k))
+            goto fail;
+
         if (pa_tagstruct_getu32(t, &length) < 0)
             goto fail;
 
@@ -633,8 +635,8 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
         if (pa_tagstruct_get_arbitrary(t, &d, length) < 0)
             goto fail;
 
-        if (pa_proplist_set(p, k, d, length) < 0)
-            goto fail;
+        if (p)
+            pa_assert_se(pa_proplist_set(p, k, d, length) >= 0);
     }
 
     return 0;

commit e17f18d89ac942252f9516e963899e4990198073
Author: Tanu Kaskinen <tanu.kaskinen at digia.com>
Date:   Fri Apr 13 14:40:31 2012 +0300

    proplist: Change proplist_name_valid() to be public function pa_proplist_key_valid().
    
    I want to check the validity in pa_tagstruct_get_proplist(),
    and I think also client applications might have use for this
    function.

diff --git a/src/map-file b/src/map-file
index 69cf25b..c6676bb 100644
--- a/src/map-file
+++ b/src/map-file
@@ -232,6 +232,7 @@ pa_proplist_get;
 pa_proplist_gets;
 pa_proplist_isempty;
 pa_proplist_iterate;
+pa_proplist_key_valid;
 pa_proplist_new;
 pa_proplist_set;
 pa_proplist_setf;
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index 649138c..2c197bc 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -44,15 +44,15 @@ struct property {
 #define MAKE_HASHMAP(p) ((pa_hashmap*) (p))
 #define MAKE_PROPLIST(p) ((pa_proplist*) (p))
 
-static pa_bool_t property_name_valid(const char *key) {
+int pa_proplist_key_valid(const char *key) {
 
     if (!pa_ascii_valid(key))
-        return FALSE;
+        return 0;
 
     if (strlen(key) <= 0)
-        return FALSE;
+        return 0;
 
-    return TRUE;
+    return 1;
 }
 
 static void property_free(struct property *prop) {
@@ -83,7 +83,7 @@ int pa_proplist_sets(pa_proplist *p, const char *key, const char *value) {
     pa_assert(key);
     pa_assert(value);
 
-    if (!property_name_valid(key) || !pa_utf8_valid(value))
+    if (!pa_proplist_key_valid(key) || !pa_utf8_valid(value))
         return -1;
 
     if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key))) {
@@ -115,7 +115,7 @@ static int proplist_setn(pa_proplist *p, const char *key, size_t key_length, con
     k = pa_xstrndup(key, key_length);
     v = pa_xstrndup(value, value_length);
 
-    if (!property_name_valid(k) || !pa_utf8_valid(v)) {
+    if (!pa_proplist_key_valid(k) || !pa_utf8_valid(v)) {
         pa_xfree(k);
         pa_xfree(v);
         return -1;
@@ -167,7 +167,7 @@ static int proplist_sethex(pa_proplist *p, const char *key, size_t key_length, c
 
     k = pa_xstrndup(key, key_length);
 
-    if (!property_name_valid(k)) {
+    if (!pa_proplist_key_valid(k)) {
         pa_xfree(k);
         return -1;
     }
@@ -214,7 +214,7 @@ int pa_proplist_setf(pa_proplist *p, const char *key, const char *format, ...) {
     pa_assert(key);
     pa_assert(format);
 
-    if (!property_name_valid(key) || !pa_utf8_valid(format))
+    if (!pa_proplist_key_valid(key) || !pa_utf8_valid(format))
         return -1;
 
     va_start(ap, format);
@@ -252,7 +252,7 @@ int pa_proplist_set(pa_proplist *p, const char *key, const void *data, size_t nb
     pa_assert(key);
     pa_assert(data || nbytes == 0);
 
-    if (!property_name_valid(key))
+    if (!pa_proplist_key_valid(key))
         return -1;
 
     if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key))) {
@@ -280,7 +280,7 @@ const char *pa_proplist_gets(pa_proplist *p, const char *key) {
     pa_assert(p);
     pa_assert(key);
 
-    if (!property_name_valid(key))
+    if (!pa_proplist_key_valid(key))
         return NULL;
 
     if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key)))
@@ -309,7 +309,7 @@ int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *
     pa_assert(data);
     pa_assert(nbytes);
 
-    if (!property_name_valid(key))
+    if (!pa_proplist_key_valid(key))
         return -1;
 
     if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key)))
@@ -349,7 +349,7 @@ int pa_proplist_unset(pa_proplist *p, const char *key) {
     pa_assert(p);
     pa_assert(key);
 
-    if (!property_name_valid(key))
+    if (!pa_proplist_key_valid(key))
         return -1;
 
     if (!(prop = pa_hashmap_remove(MAKE_HASHMAP(p), key)))
@@ -367,7 +367,7 @@ int pa_proplist_unset_many(pa_proplist *p, const char * const keys[]) {
     pa_assert(keys);
 
     for (k = keys; *k; k++)
-        if (!property_name_valid(*k))
+        if (!pa_proplist_key_valid(*k))
             return -1;
 
     for (k = keys; *k; k++)
@@ -643,7 +643,7 @@ int pa_proplist_contains(pa_proplist *p, const char *key) {
     pa_assert(p);
     pa_assert(key);
 
-    if (!property_name_valid(key))
+    if (!pa_proplist_key_valid(key))
         return -1;
 
     if (!(pa_hashmap_get(MAKE_HASHMAP(p), key)))
diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h
index 359212a..cb53cf4 100644
--- a/src/pulse/proplist.h
+++ b/src/pulse/proplist.h
@@ -279,6 +279,9 @@ pa_proplist* pa_proplist_new(void);
 /** Free the property list. \since 0.9.11 */
 void pa_proplist_free(pa_proplist* p);
 
+/** Returns a non-zero value if the key is valid. \since 3.0 */
+int pa_proplist_key_valid(const char *key);
+
 /** Append a new string entry to the property list, possibly
  * overwriting an already existing entry with the same key. An
  * internal copy of the data passed is made. Will accept only valid



More information about the pulseaudio-commits mailing list