index cb3629c89eff652d34721e33bac763415a208bf0..05e6b74d51b70117bc01a06b1b17ca9ef0f77f50 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
return attr;
} /* attr_get */
-/*
- * conditional implementations
- */
-
-static int
-attr_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond,
- sdb_store_matcher_t *filter)
-{
- sdb_attribute_t *attr;
- sdb_data_t value = SDB_DATA_INIT;
- int status;
-
- if (obj->type != SDB_HOST)
- return INT_MAX;
-
- if (sdb_store_expr_eval(ATTR_C(cond)->expr, obj, &value, filter))
- return INT_MAX;
-
- attr = attr_get(HOST(obj), ATTR_C(cond)->name, filter);
- if (! attr)
- status = INT_MAX;
- else if (attr->value.type != value.type)
- status = sdb_data_strcmp(&attr->value, &value);
- else
- status = sdb_data_cmp(&attr->value, &value);
- sdb_data_free_datum(&value);
- return status;
-} /* attr_cmp */
-
-static int
-obj_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond,
- sdb_store_matcher_t *filter)
-{
- sdb_data_t obj_value = SDB_DATA_INIT;
- sdb_data_t value = SDB_DATA_INIT;
- int status;
-
- if (sdb_store_expr_eval(OBJ_C(cond)->expr, obj, &value, filter))
- return INT_MAX;
-
- 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)) {
- status = 0;
- break;
- }
- }
- sdb_data_free_datum(&value);
- return status;
- }
-
- 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 */
-
/*
* matcher implementations
*/
return status;
} /* match_child */
-static int
-match_lt(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_LT);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status < 0);
-} /* match_lt */
-
-static int
-match_le(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_LE);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status <= 0);
-} /* match_le */
-
-static int
-match_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_EQ);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (! status);
-} /* match_eq */
-
-static int
-match_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_GE);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status >= 0);
-} /* match_ge */
-
-static int
-match_gt(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
-{
- int status;
- assert(m->type == MATCHER_GT);
- status = COND_M(m)->cond->cmp(obj, COND_M(m)->cond, filter);
- return (status != INT_MAX) && (status > 0);
-} /* match_gt */
-
/*
* cmp_expr:
* Compare the values of two expressions when evaluating them using the
* specified stored object and filter. Returns a value less than, equal to, or
* greater than zero if the value of the first expression compares less than,
* equal to, or greater than the value of the second expression. Returns
- * INT_MAX if any of the expressions could not be evaluated.
+ * INT_MAX if any of the expressions could not be evaluated or if any of them
+ * evaluated to NULL.
*/
static int
cmp_expr(sdb_store_expr_t *e1, sdb_store_expr_t *e2,
return INT_MAX;
}
- if (v1.type == v2.type)
+ if (sdb_data_isnull(&v1) || (sdb_data_isnull(&v2)))
+ status = INT_MAX;
+ else if (v1.type == v2.type)
status = sdb_data_cmp(&v1, &v2);
else
status = sdb_data_strcmp(&v1, &v2);
return (status != INT_MAX) && (status > 0);
} /* match_cmp_gt */
+static int
+match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
+ sdb_store_matcher_t *filter)
+{
+ sdb_data_t value = SDB_DATA_INIT, array = SDB_DATA_INIT;
+ int status = 1;
+
+ assert(m->type == MATCHER_IN);
+
+ if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &value, filter))
+ || (sdb_store_expr_eval(CMP_M(m)->right, obj, &array, filter)))
+ status = 0;
+
+ if (status)
+ status = sdb_data_inarray(&value, &array);
+
+ sdb_data_free_datum(&value);
+ sdb_data_free_datum(&array);
+ return status;
+} /* match_in */
+
static int
match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
sdb_store_matcher_t *filter)
free(raw);
}
- if (sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter))
+ if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter))
+ || (sdb_data_isnull(&v)))
status = 0;
else {
char value[sdb_data_strlen(&v) + 1];
match_isnull(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
sdb_store_matcher_t *filter)
{
- assert(m->type == MATCHER_ISNULL);
- if (obj->type != SDB_HOST)
- return 0;
- return attr_get(HOST(obj), ISNULL_M(m)->attr_name, filter) == NULL;
+ sdb_data_t v = SDB_DATA_INIT;
+ int status;
+
+ assert((m->type == MATCHER_ISNULL) || (m->type == MATCHER_ISNNULL));
+
+ /* TODO: this might hide real errors;
+ * improve error reporting and propagation */
+ if (sdb_store_expr_eval(ISNULL_M(m)->expr, obj, &v, filter)
+ || sdb_data_isnull(&v))
+ status = 1;
+ else
+ status = 0;
+
+ sdb_data_free_datum(&v);
+ if (m->type == MATCHER_ISNNULL)
+ return !status;
+ return status;
} /* match_isnull */
typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_obj_t *,
match_child,
match_child,
match_child,
- match_lt,
- match_le,
- match_eq,
- match_ge,
- match_gt,
match_cmp_lt,
match_cmp_le,
match_cmp_eq,
match_cmp_ne,
match_cmp_ge,
match_cmp_gt,
+ match_in,
match_regex,
match_regex,
match_isnull,
-};
-
-/*
- * private conditional types
- */
-
-static int
-attr_cond_init(sdb_object_t *obj, va_list ap)
-{
- const char *name = va_arg(ap, const char *);
- sdb_store_expr_t *expr = va_arg(ap, sdb_store_expr_t *);
-
- if (! name)
- return -1;
-
- SDB_STORE_COND(obj)->cmp = attr_cmp;
-
- ATTR_C(obj)->name = strdup(name);
- if (! ATTR_C(obj)->name)
- return -1;
- ATTR_C(obj)->expr = expr;
- sdb_object_ref(SDB_OBJ(expr));
- return 0;
-} /* attr_cond_init */
-
-static void
-attr_cond_destroy(sdb_object_t *obj)
-{
- if (ATTR_C(obj)->name)
- free(ATTR_C(obj)->name);
- sdb_object_deref(SDB_OBJ(ATTR_C(obj)->expr));
-} /* attr_cond_destroy */
-
-static sdb_type_t attr_cond_type = {
- /* size = */ sizeof(attr_cond_t),
- /* init = */ attr_cond_init,
- /* destroy = */ attr_cond_destroy,
-};
-
-static int
-obj_cond_init(sdb_object_t *obj, va_list ap)
-{
- int field = va_arg(ap, int);
- sdb_store_expr_t *expr = va_arg(ap, sdb_store_expr_t *);
-
- SDB_STORE_COND(obj)->cmp = obj_cmp;
-
- OBJ_C(obj)->field = field;
- OBJ_C(obj)->expr = expr;
- sdb_object_ref(SDB_OBJ(expr));
- return 0;
-} /* obj_cond_init */
-
-static void
-obj_cond_destroy(sdb_object_t *obj)
-{
- sdb_object_deref(SDB_OBJ(OBJ_C(obj)->expr));
-} /* obj_cond_destroy */
-
-static sdb_type_t obj_cond_type = {
- /* size = */ sizeof(obj_cond_t),
- /* init = */ obj_cond_init,
- /* destroy = */ obj_cond_destroy,
+ match_isnull,
};
/*
}
} /* string_matcher_destroy */
-static char *
-string_tostring(string_matcher_t *m, char *buf, size_t buflen)
-{
- snprintf(buf, buflen, "{ %s%s%s, %p }",
- m->name ? "'" : "", m->name ? m->name : "NULL", m->name ? "'" : "",
- m->name_re);
- return buf;
-} /* string_tostring */
-
/* initializes a name matcher */
static int
name_matcher_init(sdb_object_t *obj, va_list ap)
string_matcher_destroy(&m->name);
} /* name_matcher_destroy */
-static char *
-name_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char name[buflen + 1];
- assert(m->type == MATCHER_NAME);
- snprintf(buf, buflen, "OBJ[%s]{ NAME%s }",
- SDB_STORE_TYPE_TO_NAME(NAME_M(m)->obj_type),
- string_tostring(&NAME_M(m)->name, name, sizeof(name)));
- return buf;
-} /* name_tostring */
-
static int
attr_matcher_init(sdb_object_t *obj, va_list ap)
{
string_matcher_destroy(&attr->value);
} /* attr_matcher_destroy */
-static char *
-attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char value[buflen + 1];
-
- if (! m) {
- snprintf(buf, buflen, "ATTR{}");
- return buf;
- }
-
- assert(m->type == MATCHER_ATTR);
- snprintf(buf, buflen, "ATTR[%s]{ VALUE%s }", ATTR_M(m)->name,
- string_tostring(&ATTR_M(m)->value, value, sizeof(value)));
- return buf;
-} /* attr_tostring */
-
-static int
-cond_matcher_init(sdb_object_t *obj, va_list ap)
-{
- int type = va_arg(ap, int);
- sdb_store_cond_t *cond = va_arg(ap, sdb_store_cond_t *);
-
- if (! cond)
- return -1;
-
- sdb_object_ref(SDB_OBJ(cond));
-
- M(obj)->type = type;
- COND_M(obj)->cond = cond;
- return 0;
-} /* cond_matcher_init */
-
-static void
-cond_matcher_destroy(sdb_object_t *obj)
-{
- sdb_object_deref(SDB_OBJ(COND_M(obj)->cond));
-} /* cond_matcher_destroy */
-
-static char *
-cond_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- const char *type, *id;
- sdb_data_t value = SDB_DATA_INIT;
- char value_str[buflen];
- sdb_store_expr_t *expr;
-
- if (COND_M(m)->cond->cmp == attr_cmp) {
- type = "ATTR";
- id = ATTR_C(COND_M(m)->cond)->name;
- expr = ATTR_C(COND_M(m)->cond)->expr;
- }
- else if (COND_M(m)->cond->cmp == obj_cmp) {
- type = "OBJ";
- id = SDB_FIELD_TO_NAME(OBJ_C(COND_M(m)->cond)->field);
- expr = OBJ_C(COND_M(m)->cond)->expr;
- }
- else {
- snprintf(buf, buflen, "<unknown>");
- return buf;
- }
-
- if (sdb_store_expr_eval(expr, /* obj */ NULL, &value, /* filter */ NULL))
- snprintf(value_str, sizeof(value_str), "ERR");
- else if (sdb_data_format(&value, value_str, sizeof(value_str),
- SDB_SINGLE_QUOTED) < 0)
- snprintf(value_str, sizeof(value_str), "ERR");
- snprintf(buf, buflen, "%s[%s]{ %s %s }", type, id,
- MATCHER_SYM(m->type), value_str);
- sdb_data_free_datum(&value);
- return buf;
-} /* cond_tostring */
-
static int
op_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(OP_M(obj)->right));
} /* op_matcher_destroy */
-static char *
-op_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char left[buflen + 1], right[buflen + 1];
-
- if (! m) {
- /* this should not happen */
- snprintf(buf, buflen, "()");
- return buf;
- }
-
- assert((m->type == MATCHER_OR) || (m->type == MATCHER_AND));
- snprintf(buf, buflen, "(%s, %s, %s)",
- m->type == MATCHER_OR ? "OR" : "AND",
- sdb_store_matcher_tostring(OP_M(m)->left, left, sizeof(left)),
- sdb_store_matcher_tostring(OP_M(m)->right, right, sizeof(right)));
- return buf;
-} /* op_tostring */
-
static int
child_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(CHILD_M(obj)->m));
} /* child_matcher_destroy */
-static char *
-child_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- snprintf(buf, buflen, "%s:", MATCHER_SYM(m->type));
- buf[buflen - 1] = '\0';
- sdb_store_matcher_tostring(CHILD_M(m)->m,
- buf + strlen(buf), buflen - strlen(buf));
- return buf;
-} /* child_tostring */
-
static int
cmp_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(CMP_M(obj)->right));
} /* cmp_matcher_destroy */
-static char *
-cmp_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- if (! m) {
- /* this should not happen */
- snprintf(buf, buflen, "()");
- return buf;
- }
-
- /* TODO */
- snprintf(buf, buflen, "CMP_MATCHER(%d)", m->type);
- return buf;
-} /* cmp_tostring */
-
static int
uop_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(UOP_M(obj)->op));
} /* uop_matcher_destroy */
-static char *
-uop_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char op[buflen + 1];
-
- if (! m) {
- /* this should not happen */
- snprintf(buf, buflen, "()");
- return buf;
- }
-
- assert(m->type == MATCHER_NOT);
- snprintf(buf, buflen, "(NOT, %s)",
- sdb_store_matcher_tostring(UOP_M(m)->op, op, sizeof(op)));
- return buf;
-} /* uop_tostring */
-
static int
isnull_matcher_init(sdb_object_t *obj, va_list ap)
{
- const char *name;
-
M(obj)->type = va_arg(ap, int);
- if (M(obj)->type != MATCHER_ISNULL)
+ if ((M(obj)->type != MATCHER_ISNULL) && (M(obj)->type != MATCHER_ISNNULL))
return -1;
- name = va_arg(ap, const char *);
- if (! name)
- return -1;
- ISNULL_M(obj)->attr_name = strdup(name);
- if (! ISNULL_M(obj)->attr_name)
- return -1;
+ ISNULL_M(obj)->expr = va_arg(ap, sdb_store_expr_t *);
+ sdb_object_ref(SDB_OBJ(ISNULL_M(obj)->expr));
return 0;
} /* isnull_matcher_init */
static void
isnull_matcher_destroy(sdb_object_t *obj)
{
- if (ISNULL_M(obj)->attr_name)
- free(ISNULL_M(obj)->attr_name);
- ISNULL_M(obj)->attr_name = NULL;
+ sdb_object_deref(SDB_OBJ(ISNULL_M(obj)->expr));
+ ISNULL_M(obj)->expr = NULL;
} /* isnull_matcher_destroy */
-static char *
-isnull_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- snprintf(buf, buflen, "(IS NULL, ATTR[%s])", ISNULL_M(m)->attr_name);
- return buf;
-} /* isnull_tostring */
-
static sdb_type_t name_type = {
/* size = */ sizeof(name_matcher_t),
/* init = */ name_matcher_init,
/* destroy = */ attr_matcher_destroy,
};
-static sdb_type_t cond_type = {
- /* size = */ sizeof(cond_matcher_t),
- /* init = */ cond_matcher_init,
- /* destroy = */ cond_matcher_destroy,
-};
-
static sdb_type_t op_type = {
/* size = */ sizeof(op_matcher_t),
/* init = */ op_matcher_init,
/* destroy = */ isnull_matcher_destroy,
};
-typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t);
-
-/* this array needs to be indexable by the matcher types;
- * -> update the enum in store-private.h when updating this */
-static matcher_tostring_cb
-matchers_tostring[] = {
- op_tostring,
- op_tostring,
- uop_tostring,
- name_tostring,
- attr_tostring,
- child_tostring,
- child_tostring,
- child_tostring,
- cond_tostring,
- cond_tostring,
- cond_tostring,
- cond_tostring,
- cond_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- cmp_tostring,
- isnull_tostring,
-};
-
/*
* public API
*/
-sdb_store_cond_t *
-sdb_store_attr_cond(const char *name, sdb_store_expr_t *expr)
-{
- return SDB_STORE_COND(sdb_object_create("attr-cond", attr_cond_type,
- name, expr));
-} /* sdb_store_attr_cond */
-
-sdb_store_cond_t *
-sdb_store_obj_cond(int field, sdb_store_expr_t *expr)
-{
- return SDB_STORE_COND(sdb_object_create("obj-cond", obj_cond_type,
- field, expr));
-} /* sdb_store_obj_cond */
-
sdb_store_matcher_t *
sdb_store_name_matcher(int type, const char *name, _Bool re)
{
return M(sdb_object_create("any-matcher", child_type, type, m));
} /* sdb_store_child_matcher */
-sdb_store_matcher_t *
-sdb_store_lt_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("lt-matcher", cond_type,
- MATCHER_LT, cond));
-} /* sdb_store_lt_matcher */
-
-sdb_store_matcher_t *
-sdb_store_le_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("le-matcher", cond_type,
- MATCHER_LE, cond));
-} /* sdb_store_le_matcher */
-
-sdb_store_matcher_t *
-sdb_store_eq_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("eq-matcher", cond_type,
- MATCHER_EQ, cond));
-} /* sdb_store_eq_matcher */
-
-sdb_store_matcher_t *
-sdb_store_ge_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("ge-matcher", cond_type,
- MATCHER_GE, cond));
-} /* sdb_store_ge_matcher */
-
-sdb_store_matcher_t *
-sdb_store_gt_matcher(sdb_store_cond_t *cond)
-{
- return M(sdb_object_create("gt-matcher", cond_type,
- MATCHER_GT, cond));
-} /* sdb_store_gt_matcher */
-
/*
* TODO: Rename sdb_store_cmp_* to sdb_store_* once the old code is unused and
* has been removed.
MATCHER_CMP_GT, left, right));
} /* sdb_store_cmp_gt */
+sdb_store_matcher_t *
+sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+{
+ return M(sdb_object_create("in-matcher", cmp_type,
+ MATCHER_IN, left, right));
+} /* sdb_store_in_matcher */
+
sdb_store_matcher_t *
sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
{
} /* sdb_store_nregex_matcher */
sdb_store_matcher_t *
-sdb_store_isnull_matcher(const char *attr_name)
+sdb_store_isnull_matcher(sdb_store_expr_t *expr)
{
return M(sdb_object_create("isnull-matcher", isnull_type,
- MATCHER_ISNULL, attr_name));
+ MATCHER_ISNULL, expr));
} /* sdb_store_isnull_matcher */
+sdb_store_matcher_t *
+sdb_store_isnnull_matcher(sdb_store_expr_t *expr)
+{
+ return M(sdb_object_create("isnull-matcher", isnull_type,
+ MATCHER_ISNNULL, expr));
+} /* sdb_store_isnnull_matcher */
+
+sdb_store_matcher_op_cb
+sdb_store_parse_matcher_op(const char *op)
+{
+ if (! strcasecmp(op, "<"))
+ return sdb_store_cmp_lt;
+ else if (! strcasecmp(op, "<="))
+ return sdb_store_cmp_le;
+ else if (! strcasecmp(op, "="))
+ return sdb_store_cmp_eq;
+ else if (! strcasecmp(op, "!="))
+ return sdb_store_cmp_ne;
+ else if (! strcasecmp(op, ">="))
+ return sdb_store_cmp_ge;
+ else if (! strcasecmp(op, ">"))
+ return sdb_store_cmp_gt;
+ else if (! strcasecmp(op, "=~"))
+ return sdb_store_regex_matcher;
+ else if (! strcasecmp(op, "!~"))
+ return sdb_store_nregex_matcher;
+ return NULL;
+} /* sdb_store_parse_matcher_op */
+
int
sdb_store_parse_object_type_plural(const char *name)
{
return tmp;
} /* maybe_inv_matcher */
-static int
-parse_cond_op(const char *op,
- sdb_store_matcher_t *(**matcher)(sdb_store_cond_t *), _Bool *inv)
-{
- *inv = 0;
- if (! strcasecmp(op, "<"))
- *matcher = sdb_store_lt_matcher;
- else if (! strcasecmp(op, "<="))
- *matcher = sdb_store_le_matcher;
- else if (! strcasecmp(op, "="))
- *matcher = sdb_store_eq_matcher;
- else if (! strcasecmp(op, ">="))
- *matcher = sdb_store_ge_matcher;
- else if (! strcasecmp(op, ">"))
- *matcher = sdb_store_gt_matcher;
- else if (! strcasecmp(op, "!=")) {
- *matcher = sdb_store_eq_matcher;
- *inv = 1;
- }
- else
- return -1;
- return 0;
-} /* parse_cond_op */
-
-static sdb_store_matcher_t *
-parse_attr_cmp(const char *attr, const char *op, sdb_store_expr_t *expr)
-{
- sdb_store_matcher_t *(*matcher)(sdb_store_cond_t *) = NULL;
- sdb_store_matcher_t *m;
- sdb_store_cond_t *cond;
- _Bool inv = 0;
-
- if (! attr)
- return NULL;
-
- if (! strcasecmp(op, "IS")) {
- if (! expr)
- return sdb_store_isnull_matcher(attr);
- else
- return NULL;
- }
- else if (! expr)
- return NULL;
- else if (parse_cond_op(op, &matcher, &inv))
- return NULL;
-
- cond = sdb_store_attr_cond(attr, expr);
- if (! cond)
- return NULL;
-
- m = matcher(cond);
- /* pass ownership to 'm' or destroy in case of an error */
- sdb_object_deref(SDB_OBJ(cond));
- return maybe_inv_matcher(m, inv);
-} /* parse_attr_cmp */
-
sdb_store_matcher_t *
-sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr,
+sdb_store_matcher_parse_cmp(const char *obj_type,
const char *op, sdb_store_expr_t *expr)
{
int type = -1;
inv = 1;
re = 1;
}
- else if (type == SDB_ATTRIBUTE)
- return parse_attr_cmp(attr, op, expr);
else
return NULL;
if (sdb_store_expr_eval(expr, /* obj */ NULL, &value, /* filter */ NULL)
|| (value.type != SDB_TYPE_STRING)) {
sdb_data_free_datum(&value);
- if (type != SDB_ATTRIBUTE)
- return NULL;
- return parse_attr_cmp(attr, op, expr);
+ return NULL;
}
- if (! attr)
- m = sdb_store_name_matcher(type, value.data.string, re);
- else if (type == SDB_ATTRIBUTE)
- m = sdb_store_attr_matcher(attr, value.data.string, re);
-
+ m = sdb_store_name_matcher(type, value.data.string, re);
sdb_data_free_datum(&value);
return maybe_inv_matcher(m, inv);
} /* sdb_store_matcher_parse_cmp */
-sdb_store_matcher_t *
-sdb_store_matcher_parse_field_cmp(const char *name, const char *op,
- sdb_store_expr_t *expr)
-{
- sdb_store_matcher_t *(*matcher)(sdb_store_cond_t *) = NULL;
- sdb_store_matcher_t *m;
- sdb_store_cond_t *cond;
- _Bool inv = 0;
-
- int field;
-
- if (! expr)
- return NULL;
-
- field = sdb_store_parse_field_name(name);
- if (field < 0)
- return NULL;
-
- if (parse_cond_op(op, &matcher, &inv))
- return NULL;
- cond = sdb_store_obj_cond(field, expr);
- if (! cond)
- return NULL;
-
- assert(matcher);
- m = matcher(cond);
- /* pass ownership to 'm' or destroy in case of an error */
- sdb_object_deref(SDB_OBJ(cond));
- return maybe_inv_matcher(m, inv);
-} /* sdb_store_matcher_parse_field_cmp */
-
sdb_store_matcher_t *
sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right)
{
return matchers[m->type](m, obj, filter);
} /* sdb_store_matcher_matches */
-char *
-sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- if (! m)
- return NULL;
-
- if ((m->type < 0)
- || (((size_t)m->type >= SDB_STATIC_ARRAY_LEN(matchers_tostring))))
- return NULL;
- return matchers_tostring[m->type](m, buf, buflen);
-} /* sdb_store_matcher_tostring */
-
int
sdb_store_scan(sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
sdb_store_lookup_cb cb, void *user_data)