I want to check the validity in pa_tagstruct_get_proplist(), and I think also client applications might have use for this function. --- src/map-file | 1 + src/pulse/proplist.c | 28 ++++++++++++++-------------- src/pulse/proplist.h | 3 +++ 3 files changed, 18 insertions(+), 14 deletions(-) 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 f37e5ea..12382f5 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 -- 1.7.10