chiark / gitweb /
bus: reenable id change subscriptions
[elogind.git] / src / libsystemd-bus / bus-match.c
index f7fca5f573de962ec250927bff15a84d648b6a3a..7638f2038b4aa9ef18b2f61d618e1641e2273333 100644 (file)
@@ -755,6 +755,14 @@ int bus_match_parse(
                         escaped = false;
                 }
 
+                if (!value) {
+                        value = strdup("");
+                        if (!value) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+                }
+
                 if (t == BUS_MATCH_MESSAGE_TYPE) {
                         r = bus_message_type_from_string(value, &u);
                         if (r < 0)
@@ -808,6 +816,46 @@ fail:
         return r;
 }
 
+char *bus_match_to_string(struct bus_match_component *components, unsigned n_components) {
+        _cleanup_free_ FILE *f = NULL;
+        char *buffer = NULL;
+        size_t size = 0;
+        unsigned i;
+
+        if (n_components <= 0)
+                return strdup("");
+
+        assert(components);
+
+        f = open_memstream(&buffer, &size);
+        if (!f)
+                return NULL;
+
+        for (i = 0; i < n_components; i++) {
+                char buf[32];
+
+                if (i != 0)
+                        fputc(',', f);
+
+                fputs(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f);
+                fputc('=', f);
+                fputc('\'', f);
+
+                if (components[i].type == BUS_MATCH_MESSAGE_TYPE)
+                        fputs(bus_message_type_to_string(components[i].value_u8), f);
+                else
+                        fputs(components[i].value_str, f);
+
+                fputc('\'', f);
+        }
+
+        fflush(f);
+        if (ferror(f))
+                return NULL;
+
+        return buffer;
+}
+
 int bus_match_add(
                 struct bus_match_node *root,
                 struct bus_match_component *components,