chiark / gitweb /
bus: add macro for iterating through body parts of a message
[elogind.git] / src / libsystemd-bus / bus-internal.c
index df295539ac4afd34b2aefe5265836a9dfa9411cd..0e66f3d3553521b418308435d20b25107a044fcd 100644 (file)
@@ -171,6 +171,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 +201,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 +241,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;
+}