chiark / gitweb /
bus: reenable id change subscriptions
[elogind.git] / src / libsystemd-bus / bus-match.c
index 342819d9c06937479a033a0768a865dde715c727..7638f2038b4aa9ef18b2f61d618e1641e2273333 100644 (file)
@@ -816,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,