summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-match.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-19 03:02:45 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-19 04:40:56 +0100
commit53461b74df0576ec091275d1a5dbee00611df1ee (patch)
treef81491e1f628a7848b9096c12006d5d3b79d7686 /src/libsystemd-bus/bus-match.c
parentb43b8f7a7e088c31416374340f576887968f7cad (diff)
driverd: implement AddMatch/RemoveMatch logic
Diffstat (limited to 'src/libsystemd-bus/bus-match.c')
-rw-r--r--src/libsystemd-bus/bus-match.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index 342819d9c0..7638f2038b 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -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,