]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/conf-parser.c
resampler: Introduce work_channels
[pulseaudio] / src / pulsecore / conf-parser.c
index 95c21f00f0182f5b6293e7467d1655f72bc8fa9f..200252bb7ad567dd2d180395b5f893d36d385cdc 100644 (file)
@@ -40,7 +40,7 @@
 #define COMMENTS "#;\n"
 
 /* Run the user supplied parser for an assignment */
-static int next_assignment(pa_config_parser_state *state) {
+static int normal_assignment(pa_config_parser_state *state) {
     const pa_config_item *item;
 
     pa_assert(state);
@@ -66,6 +66,19 @@ static int next_assignment(pa_config_parser_state *state) {
     return -1;
 }
 
+/* Parse a proplist entry. */
+static int proplist_assignment(pa_config_parser_state *state) {
+    pa_assert(state);
+    pa_assert(state->proplist);
+
+    if (pa_proplist_sets(state->proplist, state->lvalue, state->rvalue) < 0) {
+        pa_log("[%s:%u] Failed to parse a proplist entry: %s = %s", state->filename, state->lineno, state->lvalue, state->rvalue);
+        return -1;
+    }
+
+    return 0;
+}
+
 /* Parse a variable assignment line */
 static int parse_line(pa_config_parser_state *state) {
     char *c;
@@ -92,7 +105,7 @@ static int parse_line(pa_config_parser_state *state) {
             }
         }
 
-        r = pa_config_parse(fn, NULL, state->item_table, state->userdata);
+        r = pa_config_parse(fn, NULL, state->item_table, state->proplist, state->userdata);
         pa_xfree(path);
         return r;
     }
@@ -110,6 +123,17 @@ static int parse_line(pa_config_parser_state *state) {
 
         pa_xfree(state->section);
         state->section = pa_xstrndup(state->lvalue + 1, k-2);
+
+        if (pa_streq(state->section, "Properties")) {
+            if (!state->proplist) {
+                pa_log("[%s:%u] \"Properties\" section is not allowed in this file.", state->filename, state->lineno);
+                return -1;
+            }
+
+            state->in_proplist = true;
+        } else
+            state->in_proplist = false;
+
         return 0;
     }
 
@@ -124,18 +148,23 @@ static int parse_line(pa_config_parser_state *state) {
     state->lvalue = pa_strip(state->lvalue);
     state->rvalue = pa_strip(state->rvalue);
 
-    return next_assignment(state);
+    if (state->in_proplist)
+        return proplist_assignment(state);
+    else
+        return normal_assignment(state);
 }
 
 /* Go through the file and parse each line */
-int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void *userdata) {
+int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, void *userdata) {
     int r = -1;
-    pa_bool_t do_close = !f;
+    bool do_close = !f;
     pa_config_parser_state state;
 
     pa_assert(filename);
     pa_assert(t);
 
+    pa_zero(state);
+
     if (!f && !(f = pa_fopen_cloexec(filename, "r"))) {
         if (errno == ENOENT) {
             pa_log_debug("Failed to open configuration file '%s': %s", filename, pa_cstrerror(errno));
@@ -147,11 +176,13 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
         goto finish;
     }
 
-    pa_zero(state);
     state.filename = filename;
     state.item_table = t;
     state.userdata = userdata;
 
+    if (proplist)
+        state.proplist = pa_proplist_new();
+
     while (!feof(f)) {
         if (!fgets(state.buf, sizeof(state.buf), f)) {
             if (feof(f))
@@ -167,9 +198,15 @@ int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, void
             goto finish;
     }
 
+    if (proplist)
+        pa_proplist_update(proplist, PA_UPDATE_REPLACE, state.proplist);
+
     r = 0;
 
 finish:
+    if (state.proplist)
+        pa_proplist_free(state.proplist);
+
     pa_xfree(state.section);
 
     if (do_close && f)
@@ -231,7 +268,7 @@ int pa_config_parse_size(pa_config_parser_state *state) {
 
 int pa_config_parse_bool(pa_config_parser_state *state) {
     int k;
-    pa_bool_t *b;
+    bool *b;
 
     pa_assert(state);
 
@@ -249,7 +286,7 @@ int pa_config_parse_bool(pa_config_parser_state *state) {
 
 int pa_config_parse_not_bool(pa_config_parser_state *state) {
     int k;
-    pa_bool_t *b;
+    bool *b;
 
     pa_assert(state);