From 3042f28a17e5c756667a0c173b377e5c15b2ee8e Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 23 Nov 2010 13:39:27 -0500 Subject: - break up %deref into %deref and %deref_f - add %deref_fr as an alias for %deref_rf --- src/format.c | 151 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 44 deletions(-) diff --git a/src/format.c b/src/format.c index c7681c3..53ddda9 100644 --- a/src/format.c +++ b/src/format.c @@ -895,47 +895,26 @@ format_first(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, * argument, pull out the values for the attribute named by the second * argument, and return a list of those values. */ static int -format_deref(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) +format_deref_x(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, + const char *fname, const char *group, const char *set, + char *ref_attr, char *target_attr, + char *filter, 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 i, j, ret, argc; + int i, j, ret; Slapi_Entry *ref; Slapi_DN *refdn; Slapi_ValueSet *ref_values, *values; Slapi_Value *ref_value, *value; int disposition, ref_disposition, buffer_flags, ref_buffer_flags; - char **argv, *attrs[3], *actual_attr, *actual_ref_attr; + char *attrs[2], *actual_attr, *actual_ref_attr; const char *cref; const struct berval *val; - char *ref_attr, *target_attr; struct berval **choices; - ret = format_parse_args(state, args, &argc, &argv); - if (ret != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: error parsing arguments\n"); - return -EINVAL; - } - if (argc != 2) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: requires two arguments\n"); - format_free_parsed_args(argv); - return -EINVAL; - } - if (outbuf_choices == NULL) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: returns a list, but a list " - "would not be appropriate\n"); - format_free_parsed_args(argv); - return -EINVAL; - } - ref_attr = argv[0]; - target_attr = argv[1]; /* Note that the attribute in this entry refers to other entries. */ if (ref_attrs != NULL) { format_add_attrlist(ref_attrs, ref_attr); @@ -945,13 +924,11 @@ format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, &ref_disposition, &actual_ref_attr, 0, &ref_buffer_flags) != 0) { /* No references means we're done, no answers to give. */ - format_free_parsed_args(argv); return -ENOENT; } /* Retrieve these attributes from the referred-to entries. */ - attrs[0] = ref_attr; - attrs[1] = target_attr; - attrs[2] = NULL; + attrs[0] = target_attr; + attrs[1] = NULL; /* Iterate through the names of the referred-to entries. */ choices = NULL; for (i = slapi_valueset_first_value(ref_values, &ref_value); @@ -966,25 +943,25 @@ format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, if (refdn == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: internal error parsing name " - "\"%s\"\n", cref); + "%s: internal error parsing name " + "\"%s\"\n", fname, cref); continue; } ref = NULL; - wrap_search_internal_get_entry(refdn, NULL, attrs, &ref, + wrap_search_internal_get_entry(refdn, filter, attrs, &ref, state->plugin_identity); if (ref == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: failure reading entry \"%s\"\n", - slapi_sdn_get_ndn(refdn)); + "%s: failure reading entry \"%s\"\n", + fname, slapi_sdn_get_ndn(refdn)); slapi_sdn_free(&refdn); continue; } slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "deref: reading \"%s\" from \"%s\"\n", - target_attr, slapi_sdn_get_ndn(refdn)); + "%s: reading \"%s\" from \"%s\"\n", + fname, target_attr, slapi_sdn_get_ndn(refdn)); slapi_sdn_free(&refdn); /* Pull out the attribute from the referred-to entry. */ if (slapi_vattr_values_get(ref, target_attr, &values, @@ -1010,7 +987,6 @@ format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, slapi_vattr_values_free(&ref_values, &actual_ref_attr, ref_buffer_flags); - format_free_parsed_args(argv); /* Return any values we found. */ if (choices != NULL) { format_add_choice(outbuf_choices, outbuf, choices); @@ -1021,6 +997,91 @@ format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, } } +static int +format_deref(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 argc, ret; + char **argv, *ref_attr, *target_attr; + ret = format_parse_args(state, args, &argc, &argv); + if (ret != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref: error parsing arguments\n"); + return -EINVAL; + } + if (argc != 2) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref: requires two arguments\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + if (outbuf_choices == NULL) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref: returns a list, but a list " + "would not be appropriate\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + ref_attr = argv[0]; + target_attr = argv[1]; + ret = format_deref_x(state, pb, e, "deref", group, set, + ref_attr, target_attr, NULL, disallowed, + outbuf, outbuf_len, outbuf_choices, + ref_attrs, inref_attrs, + ref_attr_list, inref_attr_list); + format_free_parsed_args(argv); + return ret; +} + +static int +format_deref_f(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 argc, ret; + char **argv, *ref_attr, *filter, *target_attr; + ret = format_parse_args(state, args, &argc, &argv); + if (ret != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref_f: error parsing arguments\n"); + return -EINVAL; + } + if (argc != 2) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref_f: requires two arguments\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + if (outbuf_choices == NULL) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "deref_f: returns a list, but a list " + "would not be appropriate\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + ref_attr = argv[0]; + filter = argv[1]; + target_attr = argv[2]; + ret = format_deref_x(state, pb, e, "deref_f", group, set, + ref_attr, target_attr, filter, disallowed, + outbuf, outbuf_len, outbuf_choices, + ref_attrs, inref_attrs, + ref_attr_list, inref_attr_list); + format_free_parsed_args(argv); + return ret; +} + /* For the first N-1 arguments, look up the entries matching DNs stored in the * attribute named by the argument, following the chain of named entries, and * at last, pull out the values for the attribute named by the last argument, @@ -2631,8 +2692,10 @@ format_lookup_fn(const char *fnname) } fns[] = { {"first", format_first}, {"deref", format_deref}, + {"deref_f", format_deref}, {"deref_r", format_deref_r}, {"deref_rf", format_deref_rf}, + {"deref_fr", format_deref_rf}, {"referred", format_referred}, {"referred_r", format_referred_r}, {"merge", format_merge}, -- cgit