chiark / gitweb /
timedated: use libsystemd-bus instead of libdbus for bus communication
[elogind.git] / src / libsystemd-bus / bus-internal.c
index 32713546007d37588d5a192f386c5aab0731a38e..942ac2b953be2286d1dbe0dcaf264c4d4895eec6 100644 (file)
@@ -61,9 +61,32 @@ bool object_path_is_valid(const char *p) {
         return true;
 }
 
         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 interface_name_is_valid(const char *p) {
         const char *q;
-        bool dot, found_dot;
+        bool dot, found_dot = false;
 
         if (isempty(p))
                 return 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 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;
 
         if (isempty(p))
                 return false;
@@ -229,15 +252,28 @@ bool path_simple_pattern(const char *pattern, const char *value) {
 
 int bus_message_type_from_string(const char *s, uint8_t *u) {
         if (streq(s, "signal"))
 
 int bus_message_type_from_string(const char *s, uint8_t *u) {
         if (streq(s, "signal"))
-                *u = SD_BUS_MESSAGE_TYPE_SIGNAL;
+                *u = SD_BUS_MESSAGE_SIGNAL;
         else if (streq(s, "method_call"))
         else if (streq(s, "method_call"))
-                *u = SD_BUS_MESSAGE_TYPE_METHOD_CALL;
+                *u = SD_BUS_MESSAGE_METHOD_CALL;
         else if (streq(s, "error"))
         else if (streq(s, "error"))
-                *u = SD_BUS_MESSAGE_TYPE_METHOD_ERROR;
+                *u = SD_BUS_MESSAGE_METHOD_ERROR;
         else if (streq(s, "method_return"))
         else if (streq(s, "method_return"))
-                *u = SD_BUS_MESSAGE_TYPE_METHOD_RETURN;
+                *u = SD_BUS_MESSAGE_METHOD_RETURN;
         else
                 return -EINVAL;
 
         return 0;
 }
         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;
+}