summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-11-03 17:13:39 -0500
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-11-03 17:13:39 -0500
commit2c273ef3b01d4b2e530afa1d0f8b973c62b5f439 (patch)
treee87342b082b427e8d78217dc9f04785cbe685af4 /src
parent355973e74252024dac832ed9819c91fe0e50d146 (diff)
- teach %ifeq to return lists of values correctly
Diffstat (limited to 'src')
-rw-r--r--src/format.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/format.c b/src/format.c
index 71acaf1..c95d408 100644
--- a/src/format.c
+++ b/src/format.c
@@ -2144,10 +2144,10 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
struct format_ref_attr_list ***inref_attr_list)
{
int ret, argc, i;
- unsigned int length, *lengths;
- char **argv, **values, *result;
+ unsigned int *lengths;
+ char **argv, **values;
bool_t matched;
- struct berval bv;
+ struct berval bv, **choices;
Slapi_Value *value;
ret = format_parse_args(state, args, &argc, &argv);
@@ -2163,6 +2163,8 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
format_free_parsed_args(argv);
return -EINVAL;
}
+
+ /* Evaluate the value expression to get a list of candidate values. */
values = format_get_data_set(state, e, group, set,
argv[1], disallowed,
ref_attrs, inref_attrs,
@@ -2175,6 +2177,8 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
return -EINVAL;
}
+ /* Check if any of the value expression's values match the entry's
+ * value for the named attribute. */
matched = FALSE;
value = slapi_value_new();
for (i = 0; values[i] != NULL; i++) {
@@ -2194,28 +2198,17 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
argv[0], matched ? "matches" : "doesn't match",
argv[1]);
format_free_data_set(values, lengths);
- result = format_get_data(state, e, group, set, argv[matched ? 2 : 3],
- disallowed,
- ref_attrs, inref_attrs,
- ref_attr_list, inref_attr_list,
- &length);
- if (result == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "ifelse: error evaluating \"%s\"\n",
- argv[matched ? 2 : 3]);
- format_free_parsed_args(argv);
- return -EINVAL;
- }
+
+ /* Evaluate the argument which corresponds to the output expression and
+ * return its values. */
+ ret = format_expand(state, pb, e, group, set,
+ argv[matched ? 2 : 3], disallowed,
+ outbuf, outbuf_len,
+ outbuf_choices,
+ ref_attrs, inref_attrs,
+ ref_attr_list, inref_attr_list);
format_free_parsed_args(argv);
- if ((int) length > outbuf_len) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "ifelse: out of space\n");
- format_free_data(result);
- return -ENOBUFS;
- }
- memcpy(outbuf, result, length);
- format_free_data(result);
- return length;
+ return ret;
}
/* Choose a formatting function by name. */