Exemplo n.º 1
0
static bool value_node_test(
                struct bus_match_node *node,
                enum bus_match_node_type parent_type,
                uint8_t value_u8,
                const char *value_str) {

        assert(node);
        assert(node->type == BUS_MATCH_VALUE);

        /* Tests parameters against this value node, doing prefix
         * magic and stuff. */

        switch (parent_type) {

        case BUS_MATCH_MESSAGE_TYPE:
                return node->value.u8 == value_u8;

        case BUS_MATCH_SENDER:
        case BUS_MATCH_DESTINATION:
                if (streq_ptr(node->value.str, value_str))
                        return true;

                /* FIXME: So here's an ugliness: if the match is for a
                 * well-known name then we cannot actually check this
                 * correctly here. This doesn't matter much for dbus1
                 * where no false positives exist, hence we just
                 * ignore this case here. For kdbus the messages
                 * should contain all well-known names of the sender,
                 * hence we can fix things there correctly. */

                if (node->value.str[0] != ':' && value_str && value_str[0] == ':')
                        return true;

                return false;

        case BUS_MATCH_INTERFACE:
        case BUS_MATCH_MEMBER:
        case BUS_MATCH_PATH:
        case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
                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);

        case BUS_MATCH_PATH_NAMESPACE:
                return path_simple_pattern(node->value.str, value_str);

        case BUS_MATCH_ARG_PATH ... BUS_MATCH_ARG_PATH_LAST:
                return path_complex_pattern(node->value.str, value_str);

        default:
                assert_not_reached("Invalid node type");
        }
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {

    assert_se(signature_is_single("y"));
    assert_se(signature_is_single("u"));
    assert_se(signature_is_single("v"));
    assert_se(signature_is_single("as"));
    assert_se(signature_is_single("(ss)"));
    assert_se(signature_is_single("()"));
    assert_se(signature_is_single("(()()()()())"));
    assert_se(signature_is_single("(((())))"));
    assert_se(signature_is_single("((((s))))"));
    assert_se(signature_is_single("{ss}"));
    assert_se(signature_is_single("a{ss}"));
    assert_se(!signature_is_single("uu"));
    assert_se(!signature_is_single(""));
    assert_se(!signature_is_single("("));
    assert_se(!signature_is_single(")"));
    assert_se(!signature_is_single("())"));
    assert_se(!signature_is_single("((())"));
    assert_se(!signature_is_single("{)"));
    assert_se(!signature_is_single("{}"));
    assert_se(!signature_is_single("{sss}"));
    assert_se(!signature_is_single("{s}"));
    assert_se(!signature_is_single("{ass}"));
    assert_se(!signature_is_single("a}"));

    assert_se(signature_is_pair("yy"));
    assert_se(signature_is_pair("ss"));
    assert_se(signature_is_pair("sas"));
    assert_se(signature_is_pair("sv"));
    assert_se(signature_is_pair("sa(vs)"));
    assert_se(!signature_is_pair(""));
    assert_se(!signature_is_pair("va"));
    assert_se(!signature_is_pair("sss"));
    assert_se(!signature_is_pair("{s}ss"));

    assert_se(signature_is_valid("ssa{ss}sssub", true));
    assert_se(signature_is_valid("ssa{ss}sssub", false));
    assert_se(signature_is_valid("{ss}", true));
    assert_se(!signature_is_valid("{ss}", false));
    assert_se(signature_is_valid("", true));
    assert_se(signature_is_valid("", false));

    assert_se(signature_is_valid("sssusa(uuubbba(uu)uuuu)a{u(uuuvas)}", false));

    assert_se(!signature_is_valid("a", false));
    assert_se(signature_is_valid("as", false));
    assert_se(signature_is_valid("aas", false));
    assert_se(signature_is_valid("aaas", false));
    assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad", false));
    assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas", false));
    assert_se(!signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaau", false));

    assert_se(signature_is_valid("(((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))", false));
    assert_se(!signature_is_valid("((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))", false));

    assert_se(namespace_complex_pattern("", ""));
    assert_se(namespace_complex_pattern("foobar", "foobar"));
    assert_se(namespace_complex_pattern("foobar.waldo", "foobar.waldo"));
    assert_se(namespace_complex_pattern("foobar.", "foobar.waldo"));
    assert_se(namespace_complex_pattern("foobar.waldo", "foobar."));
    assert_se(!namespace_complex_pattern("foobar.waldo", "foobar"));
    assert_se(!namespace_complex_pattern("foobar", "foobar.waldo"));
    assert_se(!namespace_complex_pattern("", "foo"));
    assert_se(!namespace_complex_pattern("foo", ""));
    assert_se(!namespace_complex_pattern("foo.", ""));

    assert_se(path_complex_pattern("", ""));
    assert_se(path_complex_pattern("", "/"));
    assert_se(path_complex_pattern("/", ""));
    assert_se(path_complex_pattern("/", "/"));
    assert_se(path_complex_pattern("/foobar/", "/"));
    assert_se(path_complex_pattern("/foobar/", "/foobar"));
    assert_se(path_complex_pattern("/foobar", "/foobar"));
    assert_se(path_complex_pattern("/foobar", "/foobar/"));
    assert_se(!path_complex_pattern("/foobar", "/foobar/waldo"));
    assert_se(path_complex_pattern("/foobar/", "/foobar/waldo"));

    assert_se(namespace_simple_pattern("", ""));
    assert_se(namespace_simple_pattern("foobar", "foobar"));
    assert_se(namespace_simple_pattern("foobar.waldo", "foobar.waldo"));
    assert_se(namespace_simple_pattern("foobar", "foobar.waldo"));
    assert_se(!namespace_simple_pattern("foobar.waldo", "foobar"));
    assert_se(!namespace_simple_pattern("", "foo"));
    assert_se(!namespace_simple_pattern("foo", ""));

    return 0;
}