diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-06-13 16:51:38 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-06-13 16:51:38 -0400 |
| commit | d2b7df5c6e434c54a808d437adde2ec4143d3048 (patch) | |
| tree | 6a311d884b22fff5e59fd3361d910cce88af2630 /src | |
| parent | 63c38f60958b465491daabc4d8d8d49b0c6f6047 (diff) | |
add "up" and "down" for forcing the case of their arguments
Diffstat (limited to 'src')
| -rw-r--r-- | src/format.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/format.c b/src/format.c index aabba07..49020fc 100644 --- a/src/format.c +++ b/src/format.c @@ -24,6 +24,7 @@ #endif #include <sys/types.h> +#include <ctype.h> #include <errno.h> #include <fnmatch.h> #include <regex.h> @@ -812,6 +813,68 @@ format_merge(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, return ret; } +/* Evaluate the only argument and upper-case it. */ +static int +format_case(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, + const char *domain, const char *map, + const char *args, char *outbuf, int outbuf_len, + char ***ref_attrs, struct format_inref_attr ***inref_attrs, + const char *fnname, int (*cb)(int)) +{ + int ret, i, j, argc, len; + char **argv; + ret = format_parse_args(state, args, &argc, &argv); + if (ret != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "%s: error parsing arguments\n", fnname); + return -EINVAL; + } + if (argc < 1) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "%s: requires at least one argument\n", fnname); + format_free_parsed_args(argv); + return -EINVAL; + } + for (i = 0, ret = 0; i < argc; i++) { + /* Get the length of this argument. */ + len = strlen(argv[i]); + /* Check that we've got space for this argument. */ + if (ret + len > outbuf_len) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "%s: out of space\n", fnname); + return -ENOBUFS; + } + /* Append the text of the argument. */ + for (j = 0; j < len; j++) { + outbuf[ret + j] = (*cb)(argv[i][j]); + } + ret += len; + } + format_free_parsed_args(argv); + return ret; +} + +static int +format_up(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, + const char *domain, const char *map, + const char *args, char *outbuf, int outbuf_len, + char ***ref_attrs, struct format_inref_attr ***inref_attrs) +{ + return format_case(state, pb, e, domain, map, args, outbuf, outbuf_len, + ref_attrs, inref_attrs, "up", toupper); +} + +static int +format_down(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, + const char *domain, const char *map, + const char *args, char *outbuf, int outbuf_len, + char ***ref_attrs, struct format_inref_attr ***inref_attrs) +{ + return format_case(state, pb, e, domain, map, args, outbuf, outbuf_len, + ref_attrs, inref_attrs, "down", tolower); +} + /* Look up the entry's values for the attribute named by the first argument, * and use the callback to check if they match the second argument. If we find * exactly one match, store it in the output buffer, otherwise store the text @@ -1143,6 +1206,8 @@ format_lookup_fn(const char *fnname) struct format_inref_attr ***inref_attrs); } fns[] = { {"echo", format_echo}, + {"up", format_up}, + {"down", format_down}, {"list", format_list}, {"deref", format_deref}, {"referred", format_referred}, |
