Code

store_lookup: Fixed lookup by back-end name.
authorSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 17:50:20 +0000 (19:50 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 5 Oct 2014 17:50:20 +0000 (19:50 +0200)
Added an integration test which reproduces the problem -- previously, all
compare operations reported a mismatch.

src/core/store_lookup.c
t/integration/simple_query.sh
t/unit/core/store_lookup_test.c

index d53bd58f35d743228ee054ccdfdd530e94360f6f..9176592723265cd2f5607a8f622473783c8a557b 100644 (file)
@@ -136,19 +136,17 @@ obj_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond,
        sdb_data_t value = SDB_DATA_INIT;
        int status;
 
-       if (sdb_store_get_field(obj, OBJ_C(cond)->field, &obj_value))
-               return INT_MAX;
        if (sdb_store_expr_eval(OBJ_C(cond)->expr, obj, &value))
                return INT_MAX;
 
-       if (obj_value.type != value.type) {
-               sdb_data_free_datum(&value);
-               return INT_MAX;
-       }
-       else if (OBJ_C(cond)->field == SDB_FIELD_BACKEND) {
+       if (OBJ_C(cond)->field == SDB_FIELD_BACKEND) {
                /* this implementation is not actually a conditional but rather checks
                 * for equality (or rather, existence) only */
                size_t i;
+
+               if (value.type != SDB_TYPE_STRING)
+                       return INT_MAX;
+
                status = INT_MAX;
                for (i = 0; i < obj->backends_num; ++i) {
                        if (! strcasecmp(obj->backends[i], value.data.string)) {
@@ -156,10 +154,20 @@ obj_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond,
                                break;
                        }
                }
+               sdb_data_free_datum(&value);
+               return status;
        }
-       else {
-               status = sdb_data_cmp(&obj_value, &value);
+
+       if (sdb_store_get_field(obj, OBJ_C(cond)->field, &obj_value))
+               return INT_MAX;
+       if (obj_value.type != value.type) {
+               sdb_data_free_datum(&obj_value);
+               sdb_data_free_datum(&value);
+               return INT_MAX;
        }
+
+       status = sdb_data_cmp(&obj_value, &value);
+       sdb_data_free_datum(&obj_value);
        sdb_data_free_datum(&value);
        return status;
 } /* obj_cmp */
index b6394432d1111cd9e9aa58ee7f58a9329dcaee83..35a55cef8a8f830716172cf351b88ba37f5e694e 100755 (executable)
@@ -152,6 +152,18 @@ output="$( run_sysdb -H "$SOCKET_FILE" \
                FILTER :last_update < 2Y" )"
 echo $output | grep -E '^\[\]$'
 
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts FILTER :backend = 'backend::mock_plugin'" )"
+echo "$output" \
+       | grep -F '"host1.example.com"' \
+       | grep -F '"host2.example.com"' \
+       | grep -F '"localhost"' \
+       | grep -F '"other.host.name"' \
+       | grep -F '"some.host.name"'
+output="$( run_sysdb -H "$SOCKET_FILE" \
+       -c "LOOKUP hosts FILTER :backend = 'invalid'" )"
+echo $output | grep -E '^\[\]$'
+
 output="$( run_sysdb -H "$SOCKET_FILE" \
        -c "LOOKUP hosts MATCHING service = 'sysdbd'" )"
 echo "$output" | grep -F '"localhost"'
index 754eb13f18808fba615ed1e809ac4d4b39a526e7..13861bbd79d6d7dcabf237095a91fe1857c9381c 100644 (file)
@@ -394,6 +394,12 @@ START_TEST(test_obj_cond)
                        { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
                { "a", SDB_FIELD_BACKEND,
                        { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+               { "a", SDB_FIELD_BACKEND,
+                       { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
+               /* (64bit) integer value without zero-bytes */
+               { "a", SDB_FIELD_BACKEND,
+                       { SDB_TYPE_INTEGER, { .integer = 0xffffffffffffffffL } },
+                       0, 0, 0, 0, 0 },
        };
 
        int status;