summaryrefslogtreecommitdiffstats
path: root/src/pulse/proplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulse/proplist.c')
-rw-r--r--src/pulse/proplist.c117
1 files changed, 113 insertions, 4 deletions
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index 93bc0034..282fe5cc 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -259,21 +259,24 @@ const char *pa_proplist_iterate(pa_proplist *p, void **state) {
return prop->key;
}
-char *pa_proplist_to_string(pa_proplist *p) {
+char *pa_proplist_to_string_sep(pa_proplist *p, const char *sep) {
const char *key;
void *state = NULL;
pa_strbuf *buf;
pa_assert(p);
+ pa_assert(sep);
buf = pa_strbuf_new();
while ((key = pa_proplist_iterate(p, &state))) {
-
const char *v;
+ if (!pa_strbuf_isempty(buf))
+ pa_strbuf_puts(buf, sep);
+
if ((v = pa_proplist_gets(p, key)))
- pa_strbuf_printf(buf, "%s = \"%s\"\n", key, v);
+ pa_strbuf_printf(buf, "%s = \"%s\"", key, v);
else {
const void *value;
size_t nbytes;
@@ -283,7 +286,7 @@ char *pa_proplist_to_string(pa_proplist *p) {
c = pa_xmalloc(nbytes*2+1);
pa_hexstr((const uint8_t*) value, nbytes, c, nbytes*2+1);
- pa_strbuf_printf(buf, "%s = hex:%s\n", key, c);
+ pa_strbuf_printf(buf, "%s = hex:%s", key, c);
pa_xfree(c);
}
}
@@ -291,6 +294,100 @@ char *pa_proplist_to_string(pa_proplist *p) {
return pa_strbuf_tostring_free(buf);
}
+char *pa_proplist_to_string(pa_proplist *p) {
+ char *s, *t;
+
+ s = pa_proplist_to_string_sep(p, "\n");
+ t = pa_sprintf_malloc("%s\n", s);
+ pa_xfree(s);
+
+ return t;
+}
+
+/* Remove all whitepsapce from the beginning and the end of *s. *s may
+ * be modified. (from conf-parser.c) */
+#define WHITESPACE " \t\n"
+#define in_string(c,s) (strchr(s,c) != NULL)
+
+static char *strip(char *s) {
+ char *b = s+strspn(s, WHITESPACE);
+ char *e, *l = NULL;
+
+ for (e = b; *e; e++)
+ if (!in_string(*e, WHITESPACE))
+ l = e;
+
+ if (l)
+ *(l+1) = 0;
+
+ return b;
+}
+
+pa_proplist *pa_proplist_from_string(const char *str) {
+ pa_proplist *p;
+ char *s, *v, *k, *e;
+
+ pa_assert(str);
+ pa_assert_se(p = pa_proplist_new());
+ pa_assert_se(s = strdup(str));
+
+ for (k = s; *k; k = e) {
+ k = k+strspn(k, WHITESPACE);
+
+ if (!*k)
+ break;
+
+ if (!(v = strchr(k, '='))) {
+ pa_log("Missing '='.");
+ break;
+ }
+
+ *v++ = '\0';
+ k = strip(k);
+
+ v = v+strspn(v, WHITESPACE);
+ if (*v == '"') {
+ v++;
+ if (!(e = strchr(v, '"'))) { /* FIXME: handle escape */
+ pa_log("Missing '\"' at end of string value.");
+ break;
+ }
+ *e++ = '\0';
+ pa_proplist_sets(p, k, v);
+ } else {
+ uint8_t *blob;
+
+ if (*v++ != 'h' || *v++ != 'e' || *v++ != 'x' || *v++ != ':') {
+ pa_log("Value must be a string or \"hex:\"");
+ break;
+ }
+
+ e = v;
+ while (in_string(*e, "0123456789abcdefABCDEF"))
+ ++e;
+
+ if ((e - v) % 2) {
+ pa_log("Invalid \"hex:\" value data");
+ break;
+ }
+
+ blob = pa_xmalloc((size_t)(e-v)/2);
+ if (pa_parsehex(v, blob, (e-v)/2) != (size_t)((e-v)/2)) {
+ pa_log("Invalid \"hex:\" value data");
+ pa_xfree(blob);
+ break;
+ }
+
+ pa_proplist_set(p, k, blob, (e-v)/2);
+ pa_xfree(blob);
+ }
+ }
+
+ pa_xfree(s);
+
+ return p;
+}
+
int pa_proplist_contains(pa_proplist *p, const char *key) {
pa_assert(p);
pa_assert(key);
@@ -322,3 +419,15 @@ pa_proplist* pa_proplist_copy(pa_proplist *template) {
return p;
}
+
+unsigned pa_proplist_size(pa_proplist *p) {
+ pa_assert(p);
+
+ return pa_hashmap_size(MAKE_HASHMAP(p));
+}
+
+int pa_proplist_isempty(pa_proplist *p) {
+ pa_assert(p);
+
+ return pa_hashmap_isempty(MAKE_HASHMAP(p));
+}