X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fbus-internal.c;h=942ac2b953be2286d1dbe0dcaf264c4d4895eec6;hp=d27b3f466bea7b4f363eb2c7d65697c86dcfd874;hb=40ca29a1370379d43e44c0ed425eecc7218dcbca;hpb=6693860fab7e34ffc59a748d3064d553fba25f2c diff --git a/src/libsystemd-bus/bus-internal.c b/src/libsystemd-bus/bus-internal.c index d27b3f466..942ac2b95 100644 --- a/src/libsystemd-bus/bus-internal.c +++ b/src/libsystemd-bus/bus-internal.c @@ -61,9 +61,32 @@ bool object_path_is_valid(const char *p) { return true; } +char* object_path_startswith(const char *a, const char *b) { + const char *p; + + if (!object_path_is_valid(a) || + !object_path_is_valid(b)) + return NULL; + + if (streq(b, "/")) + return (char*) a + 1; + + p = startswith(a, b); + if (!p) + return NULL; + + if (*p == 0) + return (char*) p; + + if (*p == '/') + return (char*) p + 1; + + return NULL; +} + bool interface_name_is_valid(const char *p) { const char *q; - bool dot, found_dot; + bool dot, found_dot = false; if (isempty(p)) return false; @@ -103,7 +126,7 @@ bool interface_name_is_valid(const char *p) { bool service_name_is_valid(const char *p) { const char *q; - bool dot, found_dot, unique; + bool dot, found_dot = false, unique; if (isempty(p)) return false; @@ -141,7 +164,6 @@ bool service_name_is_valid(const char *p) { return false; return true; - } bool member_name_is_valid(const char *p) { @@ -168,3 +190,90 @@ 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; + + if (!a && !b) + return true; + + if (!a || !b) + return 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) { + + if (!a && !b) + return true; + + if (!a || !b) + return false; + + 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_SIGNAL; + else if (streq(s, "method_call")) + *u = SD_BUS_MESSAGE_METHOD_CALL; + else if (streq(s, "error")) + *u = SD_BUS_MESSAGE_METHOD_ERROR; + else if (streq(s, "method_return")) + *u = SD_BUS_MESSAGE_METHOD_RETURN; + else + return -EINVAL; + + return 0; +} + +const char *bus_message_type_to_string(uint8_t u) { + if (u == SD_BUS_MESSAGE_SIGNAL) + return "signal"; + else if (u == SD_BUS_MESSAGE_METHOD_CALL) + return "method_call"; + else if (u == SD_BUS_MESSAGE_METHOD_ERROR) + return "error"; + else if (u == SD_BUS_MESSAGE_METHOD_RETURN) + return "method_return"; + else + return NULL; +}