diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/format.c | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/src/format.c b/src/format.c index 4a10e3e..9dba9f7 100644 --- a/src/format.c +++ b/src/format.c @@ -1191,14 +1191,14 @@ format_deref_f(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, * and return a list of those values. */ static int format_deref_rx(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, - const char *fname, const char *group, const char *set, - const char **attributes, const char **filters, + const char *fname, const char *group, const char *set, + const char **attributes, const char **filters, 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) + 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 i, j, k, argc; Slapi_Entry *entry; @@ -1390,13 +1390,13 @@ format_deref_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, static int format_deref_rf(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) + 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, n, i; char **argv, **attrs, **filters; @@ -1515,11 +1515,11 @@ format_referred_entry_cb(Slapi_Entry *e, void *callback_data) } static int format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, - const char *group, const char *set, + 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, + 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) { @@ -2054,7 +2054,7 @@ format_match_generic(struct plugin_state *state, struct format_ref_attr_list ***inref_attr_list, const char *fnname, char * (*match_fn)(const char *pattern, const char *value, - char **argv)) + char **argv)) { char *cvalue, **argv, **matches, **values, *plugin_id, *default_value; int i, count, argc, ret, len; @@ -2254,24 +2254,30 @@ format_match(struct plugin_state *state, /* Check for a regex match. */ static char * -format_regmatch_cb(const char *pattern, const char *value, char **argv) +format_regmatch_base_cb(const char *pattern, int cflags, + const char *value, char **argv) { regex_t reg; regmatch_t matches; bool_t matched; memset(®, 0, sizeof(reg)); - if (regcomp(®, pattern, REG_EXTENDED | REG_NOSUB) != 0) { + if (regcomp(®, pattern, REG_EXTENDED | REG_NOSUB | cflags) != 0) { return NULL; } matched = (regexec(®, value, 1, &matches, 0) == 0); regfree(®); return matched ? strdup(value) : NULL; } +static char * +format_regmatch_cb(const char *pattern, const char *value, char **argv) +{ + return format_regmatch_base_cb(patter, 0, value, argv); +} static int format_regmatch(struct plugin_state *state, - Slapi_PBlock *pb, Slapi_Entry *e, + Slapi_PBlock *pb, Slapi_Entry *e, const char *group, const char *set, - const char *args, const char *disallowed, + 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, @@ -2285,10 +2291,34 @@ format_regmatch(struct plugin_state *state, ref_attr_list, inref_attr_list, "format_regmatch", format_regmatch_cb); } +static char * +format_regmatchi_cb(const char *pattern, const char *value, char **argv) +{ + return format_regmatch_base_cb(patter, REG_ICASE, value, argv); +} +static int +format_regmatchi(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) +{ + return format_match_generic(state, pb, e, group, set, args, 2, 2, + disallowed, + outbuf, outbuf_len, outbuf_choices, + ref_attrs, inref_attrs, + ref_attr_list, inref_attr_list, + "format_regmatchi", format_regmatchi_cb); +} /* Check for a regex match and build a custom result from the matching value. */ static char * -format_regsub_cb(const char *pattern, const char *value, char **argv) +format_regsub_base_cb(const char *pattern, int cflags, + const char *value, char **argv) { regex_t reg; regmatch_t matches[10]; @@ -2296,7 +2326,7 @@ format_regsub_cb(const char *pattern, const char *value, char **argv) int i, j, m, len; char *template, *ret; memset(®, 0, sizeof(reg)); - if (regcomp(®, pattern, REG_EXTENDED) != 0) { + if (regcomp(®, pattern, REG_EXTENDED | cflags) != 0) { return NULL; } memset(&matches, 0, sizeof(matches)); @@ -2331,7 +2361,7 @@ format_regsub_cb(const char *pattern, const char *value, char **argv) m = template[i] - '0'; if (matches[m].rm_so != -1) { len += (matches[m].rm_eo - - matches[m].rm_so); + matches[m].rm_so); } continue; break; @@ -2394,6 +2424,11 @@ format_regsub_cb(const char *pattern, const char *value, char **argv) ret[j] = '\0'; return ret; } +static char * +format_regsub_cb(const char *pattern, const char *value, char **argv) +{ + return format_regsub_base_cb(patter, 0, value, argv); +} static int format_regsub(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, @@ -2412,6 +2447,29 @@ format_regsub(struct plugin_state *state, ref_attr_list, inref_attr_list, "format_regsub", format_regsub_cb); } +static char * +format_regsubi_cb(const char *pattern, const char *value, char **argv) +{ + return format_regsub_base_cb(patter, REG_ICASE, value, argv); +} +static int +format_regsubi(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) +{ + return format_match_generic(state, pb, e, group, set, args, 3, 3, + disallowed, + outbuf, outbuf_len, outbuf_choices, + ref_attrs, inref_attrs, + ref_attr_list, inref_attr_list, + "format_regsubi", format_regsubi_cb); +} /* If the attribute given by the first argument is equal to the value given in * the second, return the third, else return the fourth. We used to allow an @@ -2816,7 +2874,9 @@ format_lookup_fn(const char *fnname) {"merge", format_merge}, {"match", format_match}, {"regmatch", format_regmatch}, + {"regmatchi", format_regmatchi}, {"regsub", format_regsub}, + {"regsubi", format_regsubi}, {"ifeq", format_ifeq}, {"collect", format_collect}, {"link", format_link}, @@ -3331,10 +3391,10 @@ format_expand(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, char *subexp, *fnname, *params, *spd_id; const char *paramstart, *paramend; int (*formatfn)(struct plugin_state *state, - Slapi_PBlock *pb, Slapi_Entry *e, + Slapi_PBlock *pb, Slapi_Entry *e, const char *group, const char *set, const char *args, const char *disallowed, - char *outbuf, int outbuf_len, + char *outbuf, int outbuf_len, struct format_choice **outbuf_choices, char ***ref_attrs, struct format_inref_attr ***inref_attrs, |
