diff options
author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-11-03 18:22:59 -0500 |
---|---|---|
committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-11-03 18:22:59 -0500 |
commit | ce453beffb395046773f91f9c161dc4c0069863f (patch) | |
tree | 24930f17eed4d7ea493ba8607ab37be55244470d /src | |
parent | 433d423405a49d8b4082c665fd2112ce4b3c7aa9 (diff) | |
download | slapi-nis-ce453beffb395046773f91f9c161dc4c0069863f.tar.gz slapi-nis-ce453beffb395046773f91f9c161dc4c0069863f.tar.xz slapi-nis-ce453beffb395046773f91f9c161dc4c0069863f.zip |
- add a %collect function, for concatenating lists of values into single
lists, but without flattening them as %merge does
Diffstat (limited to 'src')
-rw-r--r-- | src/format.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/format.c b/src/format.c index c95d408..c09fef5 100644 --- a/src/format.c +++ b/src/format.c @@ -2211,6 +2211,63 @@ format_ifeq(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, return ret; } +/* Evaluate all of the arguments, and concatentate all of the lists of results + * to produce one long list. */ +static int +format_collect(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 ***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, j; + unsigned int *lengths; + char **argv, **values; + bool_t matched; + struct berval bv, **choices; + Slapi_Value *value; + + ret = format_parse_args(state, args, &argc, &argv); + if (argc < 1) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "collect: error parsing arguments\n"); + return -EINVAL; + } + + /* Walk the list of the arguments. */ + choices = NULL; + for (i = 0; i < argc; i++) { + /* Evaluate this argument. */ + values = format_get_data_set(state, e, group, set, + argv[i], disallowed, + ref_attrs, inref_attrs, + ref_attr_list, inref_attr_list, + &lengths); + if (values != NULL) { + /* Walk the list of values. */ + for (j = 0; values[j] != NULL; j++) { + /* Add it to the list. */ + bv.bv_val = values[j]; + bv.bv_len = lengths[j]; + format_add_bv_list(&choices, &bv); + } + format_free_data_set(values, lengths); + } + } + + if (choices != NULL) { + format_add_choice(outbuf_choices, outbuf, choices); + format_free_bv_list(choices); + } + + format_free_parsed_args(argv); + + return 0; +} + /* Choose a formatting function by name. */ static void * format_lookup_fn(const char *fnname) @@ -2239,6 +2296,7 @@ format_lookup_fn(const char *fnname) {"regmatch", format_regmatch}, {"regsub", format_regsub}, {"ifeq", format_ifeq}, + {"collect", format_collect}, }; for (i = 0; i < sizeof(fns) / sizeof(fns[0]); i++) { if ((fns[i].name != NULL) && |