diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-07-02 16:15:52 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-07-02 16:15:52 -0400 |
| commit | 2a14b1cf3a8a5756a3deb78a636003b92ddb15a8 (patch) | |
| tree | 5a16c02c218dbdc1b35e971a6943d0e33769f26c /src/format.c | |
| parent | e7a2274b2812194fc2dd9c5fc73f90a131739d64 (diff) | |
- teach referred() to return multiple choices
Diffstat (limited to 'src/format.c')
| -rw-r--r-- | src/format.c | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/format.c b/src/format.c index f06d548..bc64a6c 100644 --- a/src/format.c +++ b/src/format.c @@ -600,8 +600,8 @@ format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, if (len == 0) { continue; } - /* If we have the option of storing multiple answers, - * do that. */ + /* If we're keeping a list of choices, just add it to + * the list of values we've retrieved and keep going. */ if (outbuf_choices != NULL) { backend_shr_add_strlist(&choices, cvalue); continue; @@ -657,6 +657,8 @@ struct format_referred_cbdata { char *attr, *separator; char *outbuf; int outbuf_len; + struct format_choice **outbuf_choices; + char **choices; int count; int ret; }; @@ -702,8 +704,14 @@ format_referred_entry_cb(Slapi_Entry *e, void *callback_data) slapi_log_error(SLAPI_LOG_PLUGIN, cbdata->state->plugin_desc->spd_id, "referred: got value \"%s\"\n", cvalue); - slen = strlen(cbdata->separator); + /* If we're keeping a list of choices, just add it to the list + * of values we've retrieved and keep going. */ + if (cbdata->outbuf_choices != NULL) { + backend_shr_add_strlist(&cbdata->choices, cvalue); + continue; + } /* Check if there's space for the value. */ + slen = strlen(cbdata->separator); if (len + (cbdata->count ? slen : 0) > cbdata->outbuf_len) { slapi_log_error(SLAPI_LOG_PLUGIN, cbdata->state->plugin_desc->spd_id, @@ -740,8 +748,8 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, { int i, ret, argc; Slapi_PBlock *local_pb; - char **argv, *attrs[2], *filter, *tndn; - char *set_filter, **set_bases, *use_filter; + char **argv, *attrs[2], *filter, *tndn, *sep, *attr, *other_attr; + char *other_set, *set_filter, **set_bases, *use_filter; struct format_referred_cbdata cbdata; ret = format_parse_args(state, args, &argc, &argv); @@ -750,15 +758,34 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, "referred: error parsing arguments\n"); return -EINVAL; } - if (argc != 4) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "referred: requires 4 arguments\n"); - format_free_parsed_args(argv); - return -EINVAL; + if (outbuf_choices == NULL) { + if (argc != 4) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "referred: requires 4 arguments\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + sep = argv[0]; + other_set = argv[1]; + other_attr = argv[2]; + attr = argv[3]; + } else { + if (argc != 3) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "referred: requires 3 arguments\n"); + format_free_parsed_args(argv); + return -EINVAL; + } + sep = NULL; + other_set = argv[0]; + other_attr = argv[1]; + attr = argv[2]; } /* Build the attribute list. */ - attrs[0] = argv[3]; + attrs[0] = attr; attrs[1] = NULL; /* Set up to search for matches. */ @@ -770,27 +797,31 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, return -ENOMEM; } cbdata.state = state; - cbdata.attr = argv[3]; - cbdata.separator = argv[0]; + cbdata.attr = attr; + cbdata.separator = sep; cbdata.outbuf = outbuf; cbdata.outbuf_len = outbuf_len; + cbdata.outbuf_choices = outbuf_choices; + cbdata.choices = NULL; cbdata.count = 0; cbdata.ret = 0; /* Retrieve the map-specific paramters. */ set_filter = NULL; set_bases = NULL; - backend_get_set_config(state, group, argv[1], &set_bases, &set_filter); + backend_get_set_config(state, group, other_set, + &set_bases, &set_filter); if (set_bases == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "no search bases defined for \"%s\"/\"%s\"?\n", - group, argv[1]); + group, other_set); } /* Note that the attribute in this map refers to this entry. */ if (inref_attrs != NULL) { - format_add_inref_attrs(inref_attrs, group, argv[1], argv[2]); + format_add_inref_attrs(inref_attrs, group, + other_set, other_attr); } tndn = format_escape_for_filter(slapi_entry_get_ndn(e)); @@ -808,7 +839,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, use_filter = set_filter ? set_filter : "(objectClass=*)"; for (i = 0; (set_bases != NULL) && (set_bases[i] != NULL); i++) { /* Build the search filter. */ - filter = malloc(strlen(use_filter) + strlen(argv[2]) + + filter = malloc(strlen(use_filter) + strlen(other_attr) + strlen(tndn) + 7); if (filter == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, @@ -819,7 +850,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, format_free_parsed_args(argv); return -ENOMEM; } - sprintf(filter, "(&(%s=%s)%s)", argv[2], tndn, use_filter); + sprintf(filter, "(&(%s=%s)%s)", other_attr, tndn, use_filter); /* Set up the search. */ slapi_search_internal_set_pb(local_pb, set_bases[i], LDAP_SCOPE_SUB, @@ -843,6 +874,11 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, } free(tndn); + if ((outbuf_choices != NULL) && (cbdata.choices != NULL)) { + format_add_choice(outbuf_choices, outbuf, cbdata.choices); + backend_shr_free_strlist(cbdata.choices); + } + backend_free_set_config(set_bases, set_filter); slapi_pblock_destroy(local_pb); format_free_parsed_args(argv); |
