diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-31 16:16:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-31 16:16:37 +0200 |
commit | 392d5b378ceae5e1fd7c91ca545fcf4cd105744a (patch) | |
tree | e231fe77155323de76b535cd509ee5677f1bf28f /src/libsystemd-bus/bus-internal.c | |
parent | 11c4c2492083325531aeb3eeb9b041c929677890 (diff) |
bus: parse matches locally and allow registration of callbacks for them
This includes code to parse and split up match strings which will also
be useful to calculate bloom filter masks when the time comes.
Diffstat (limited to 'src/libsystemd-bus/bus-internal.c')
-rw-r--r-- | src/libsystemd-bus/bus-internal.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-internal.c b/src/libsystemd-bus/bus-internal.c index d27b3f466b..317f6a8a9c 100644 --- a/src/libsystemd-bus/bus-internal.c +++ b/src/libsystemd-bus/bus-internal.c @@ -168,3 +168,64 @@ bool member_name_is_valid(const char *p) { return true; } + +static bool complex_pattern_check(char c, const char *a, const char *b) { + bool separator = false; + + for (;;) { + if (*a != *b) + return (separator && (*a == 0 || *b == 0)) || + (*a == 0 && *b == c && b[1] == 0) || + (*b == 0 && *a == c && a[1] == 0); + + if (*a == 0) + return true; + + separator = *a == c; + + a++, b++; + } +} + +bool namespace_complex_pattern(const char *pattern, const char *value) { + return complex_pattern_check('.', pattern, value); +} + +bool path_complex_pattern(const char *pattern, const char *value) { + return complex_pattern_check('/', pattern, value); +} + +static bool simple_pattern_check(char c, const char *a, const char *b) { + for (;;) { + if (*a != *b) + return *a == 0 && *b == c; + + if (*a == 0) + return true; + + a++, b++; + } +} + +bool namespace_simple_pattern(const char *pattern, const char *value) { + return simple_pattern_check('.', pattern, value); +} + +bool path_simple_pattern(const char *pattern, const char *value) { + return simple_pattern_check('/', pattern, value); +} + +int bus_message_type_from_string(const char *s, uint8_t *u) { + if (streq(s, "signal")) + *u = SD_BUS_MESSAGE_TYPE_SIGNAL; + else if (streq(s, "method_call")) + *u = SD_BUS_MESSAGE_TYPE_METHOD_CALL; + else if (streq(s, "error")) + *u = SD_BUS_MESSAGE_TYPE_METHOD_ERROR; + else if (streq(s, "method_return")) + *u = SD_BUS_MESSAGE_TYPE_METHOD_RETURN; + else + return -EINVAL; + + return 0; +} |