summaryrefslogtreecommitdiffstats
path: root/src/format.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@dahyabhai.net>2012-03-28 18:11:28 -0400
committerNalin Dahyabhai <nalin@dahyabhai.net>2012-03-28 18:11:28 -0400
commitb0c7b3bfe85fdda5fe15a1e39e2c3c99e6352bb8 (patch)
tree5093d589bf98f0e76ed2a5f09c9face572839cc3 /src/format.c
parent6d78b63916f725300472b28c3c7b283afc72ac2e (diff)
downloadslapi-nis-b0c7b3bfe85fdda5fe15a1e39e2c3c99e6352bb8.tar.gz
slapi-nis-b0c7b3bfe85fdda5fe15a1e39e2c3c99e6352bb8.tar.xz
slapi-nis-b0c7b3bfe85fdda5fe15a1e39e2c3c99e6352bb8.zip
- add a "default" function
Diffstat (limited to 'src/format.c')
-rw-r--r--src/format.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/format.c b/src/format.c
index 2d18da7..aed71f1 100644
--- a/src/format.c
+++ b/src/format.c
@@ -2703,6 +2703,55 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
return ret;
}
+/* If the expression given as the first argument returns any values, return
+ * them. Otherwise, return the second expression. */
+static int
+format_default(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
+ const char *group, const char *set,
+ const char *args, const char *disallowed,
+ char *outbuf, int outbuf_len,
+ struct format_choice **outbuf_choices,
+ char ***rel_attrs, char ***ref_attrs,
+ struct format_inref_attr ***inref_attrs,
+ struct format_ref_attr_list ***ref_attr_list,
+ struct format_ref_attr_list ***inref_attr_list)
+{
+ int ret, argc, i;
+ unsigned int *lengths;
+ char **argv, **values;
+ bool_t first;
+ struct berval bv, **choices;
+
+ ret = format_parse_args(state, args, &argc, &argv);
+ if (ret != 0) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "default: error parsing arguments\n");
+ return -EINVAL;
+ }
+ if (argc < 2) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "default: expected at least two arguments "
+ "(got %d)\n",
+ argc);
+ format_free_parsed_args(argv);
+ return -EINVAL;
+ }
+ /* Evaluate expressions until we run out of them or succeed. */
+ for (i = 0; i < argc; i++) {
+ ret = format_expand(state, pb, e, group, set,
+ argv[i], disallowed,
+ outbuf, outbuf_len,
+ outbuf_choices,
+ rel_attrs, ref_attrs, inref_attrs,
+ ref_attr_list, inref_attr_list);
+ if (ret >= 0) {
+ break;
+ }
+ }
+ format_free_parsed_args(argv);
+ return ret;
+}
+
/* Evaluate all of the arguments, and concatentate all of the lists of results
* to produce one long list. */
static int
@@ -3200,6 +3249,7 @@ format_lookup_fn(const char *fnname)
{"mregsub", format_mregsub},
{"mregsubi", format_mregsubi},
{"ifeq", format_ifeq},
+ {"default", format_default},
{"collect", format_collect},
{"link", format_link},
{"unique", format_unique},