chiark / gitweb /
libsystemd-bus: add lightweight object vtable implementation for exposing objects...
[elogind.git] / src / libsystemd-bus / bus-internal.c
index df295539ac4afd34b2aefe5265836a9dfa9411cd..afff7bd7c1253a41c184709ff4d757159d24c2e5 100644 (file)
@@ -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;
@@ -171,6 +194,12 @@ bool member_name_is_valid(const char *p) {
 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)) ||
@@ -195,6 +224,13 @@ bool path_complex_pattern(const char *pattern, const char *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;
@@ -228,3 +264,16 @@ int bus_message_type_from_string(const char *s, uint8_t *u) {
 
         return 0;
 }
+
+const char *bus_message_type_to_string(uint8_t u) {
+        if (u == SD_BUS_MESSAGE_TYPE_SIGNAL)
+                return "signal";
+        else if (u == SD_BUS_MESSAGE_TYPE_METHOD_CALL)
+                return "method_call";
+        else if (u == SD_BUS_MESSAGE_TYPE_METHOD_ERROR)
+                return "error";
+        else if (u == SD_BUS_MESSAGE_TYPE_METHOD_RETURN)
+                 return "method_return";
+        else
+                return NULL;
+}