diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-14 17:45:26 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-14 17:45:26 +0200 |
commit | 42c5aaf3ba3eb9e11a1a2cad105e0dd956ac9763 (patch) | |
tree | 231405000cd34664efddba48e7719f750d088c4f /src | |
parent | ed5c5dbde1575d74c87ae9856fe61268d7ae8f4b (diff) |
bus: fix counting of argN= matches
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-internal.c | 13 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-match.c | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 14 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-match.c | 16 |
4 files changed, 27 insertions, 18 deletions
diff --git a/src/libsystemd-bus/bus-internal.c b/src/libsystemd-bus/bus-internal.c index df295539ac..3271354600 100644 --- a/src/libsystemd-bus/bus-internal.c +++ b/src/libsystemd-bus/bus-internal.c @@ -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; diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c index 37e7cc71f3..01434b33b5 100644 --- a/src/libsystemd-bus/bus-match.c +++ b/src/libsystemd-bus/bus-match.c @@ -146,7 +146,7 @@ static bool value_node_test( case BUS_MATCH_MEMBER: case BUS_MATCH_PATH: case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST: - return streq(node->value.str, value_str); + return streq_ptr(node->value.str, value_str); case BUS_MATCH_ARG_NAMESPACE ... BUS_MATCH_ARG_NAMESPACE_LAST: return namespace_simple_pattern(node->value.str, value_str); diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index e970d093cb..103e2c1f65 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -3263,8 +3263,8 @@ int bus_message_read_strv_extend(sd_bus_message *m, char ***l) { const char* bus_message_get_arg(sd_bus_message *m, unsigned i) { int r; - const char *t; - char type; + const char *t = NULL; + unsigned j; assert(m); @@ -3272,7 +3272,9 @@ const char* bus_message_get_arg(sd_bus_message *m, unsigned i) { if (r < 0) return NULL; - while (i > 0) { + for (j = 0; j <= i; j++) { + char type; + r = sd_bus_message_peek_type(m, &type, NULL); if (r < 0) return NULL; @@ -3285,14 +3287,8 @@ const char* bus_message_get_arg(sd_bus_message *m, unsigned i) { r = sd_bus_message_read_basic(m, type, &t); if (r < 0) return NULL; - - i--; } - r = sd_bus_message_rewind(m, true); - if (r < 0) - return NULL; - return t; } diff --git a/src/libsystemd-bus/test-bus-match.c b/src/libsystemd-bus/test-bus-match.c index ccbea815e7..9cf994009d 100644 --- a/src/libsystemd-bus/test-bus-match.c +++ b/src/libsystemd-bus/test-bus-match.c @@ -63,10 +63,10 @@ int main(int argc, char *argv[]) { zero(root); root.type = BUS_MATCH_ROOT; - assert_se(bus_match_add(&root, "arg3='wal\\'do',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(1), NULL) >= 0); - assert_se(bus_match_add(&root, "arg3='wal\\'do2',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(2), NULL) >= 0); - assert_se(bus_match_add(&root, "arg4='test',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(3), NULL) >= 0); - assert_se(bus_match_add(&root, "arg4='test',sender='foo',type='method_call',interface='bar',", filter, INT_TO_PTR(4), NULL) >= 0); + assert_se(bus_match_add(&root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(1), NULL) >= 0); + assert_se(bus_match_add(&root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(2), NULL) >= 0); + assert_se(bus_match_add(&root, "arg3='test',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(3), NULL) >= 0); + assert_se(bus_match_add(&root, "arg3='test',sender='foo',type='method_call',interface='bar',", filter, INT_TO_PTR(4), NULL) >= 0); assert_se(bus_match_add(&root, "", filter, INT_TO_PTR(5), NULL) >= 0); assert_se(bus_match_add(&root, "interface='quux'", filter, INT_TO_PTR(6), NULL) >= 0); assert_se(bus_match_add(&root, "interface='bar'", filter, INT_TO_PTR(7), NULL) >= 0); @@ -74,9 +74,9 @@ int main(int argc, char *argv[]) { assert_se(bus_match_add(&root, "path='/foo/bar'", filter, INT_TO_PTR(9), NULL) >= 0); assert_se(bus_match_add(&root, "path_namespace='/foo'", filter, INT_TO_PTR(10), NULL) >= 0); assert_se(bus_match_add(&root, "path_namespace='/foo/quux'", filter, INT_TO_PTR(11), NULL) >= 0); - assert_se(bus_match_add(&root, "arg2='two'", filter, INT_TO_PTR(12), NULL) >= 0); - assert_se(bus_match_add(&root, "member='waldo',arg3path='/prefix/'", filter, INT_TO_PTR(13), NULL) >= 0); - assert_se(bus_match_add(&root, "member='waldo',path='/foo/bar',arg4namespace='prefix'", filter, INT_TO_PTR(14), NULL) >= 0); + assert_se(bus_match_add(&root, "arg1='two'", filter, INT_TO_PTR(12), NULL) >= 0); + assert_se(bus_match_add(&root, "member='waldo',arg2path='/prefix/'", filter, INT_TO_PTR(13), NULL) >= 0); + assert_se(bus_match_add(&root, "member='waldo',path='/foo/bar',arg3namespace='prefix'", filter, INT_TO_PTR(14), NULL) >= 0); bus_match_dump(&root, 0); @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) { assert_se(mask_contains((unsigned[]) { 9, 8, 7, 5, 10, 12, 13, 14 }, 8)); assert_se(bus_match_remove(&root, "member='waldo',path='/foo/bar'", filter, INT_TO_PTR(8)) > 0); - assert_se(bus_match_remove(&root, "arg3path='/prefix/',member='waldo'", filter, INT_TO_PTR(13)) > 0); + assert_se(bus_match_remove(&root, "arg2path='/prefix/',member='waldo'", filter, INT_TO_PTR(13)) > 0); assert_se(bus_match_remove(&root, "interface='barxx'", filter, INT_TO_PTR(7)) == 0); bus_match_dump(&root, 0); |