summaryrefslogtreecommitdiffstats
path: root/src/format.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-10-24 15:49:47 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-10-24 15:49:47 -0400
commit73eb5f500c6d22f03a65dad2e3a061c7d897c819 (patch)
tree953d4df7f6e2e627cc929a72f5f2601ae953998a /src/format.c
parentf0933150a9764eee648c0fa4d591531e7c0cf9b9 (diff)
- rework how the referred_r function works, so that it retrieves the
interesting attribute from intermediate points, as deref_r does
Diffstat (limited to 'src/format.c')
-rw-r--r--src/format.c161
1 files changed, 74 insertions, 87 deletions
diff --git a/src/format.c b/src/format.c
index 00237a0..e0d6e06 100644
--- a/src/format.c
+++ b/src/format.c
@@ -1344,18 +1344,67 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
}
/* Add the name of this entry to the DN list in the cbdata. */
-struct format_note_entry_sdn_cbdata {
+struct format_referred_r_entry_cbdata {
struct plugin_state *state;
+ char *attribute;
+ struct berval ***choices;
Slapi_DN ***sdn_list;
};
static int
-format_note_entry_sdn_cb(Slapi_Entry *e, void *cbdata_ptr)
+format_referred_r_entry_cb(Slapi_Entry *e, void *cbdata_ptr)
{
- struct format_note_entry_sdn_cbdata *cbdata = cbdata_ptr;
+ struct format_referred_r_entry_cbdata *cbdata = cbdata_ptr;
+ const struct berval *bval;
+ Slapi_DN *sdn;
+ Slapi_ValueSet *values;
+ Slapi_Value *value;
+ int i, disposition, buffer_flags;
+ char *actual_attr;
+
+ /* Note that we visited this entry. */
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata->state->plugin_desc->spd_id,
"search matched entry \"%s\"\n", slapi_entry_get_dn(e));
format_add_sdn_list(cbdata->sdn_list, slapi_entry_get_dn(e));
+ sdn = slapi_entry_get_sdn(e);
+
+ /* If we're also being asked to pull values out of the entry... */
+ if ((cbdata->attribute != NULL) && (cbdata->choices != NULL)) {
+ /* Pull up the value set. */
+ if (slapi_vattr_values_get(e, cbdata->attribute, &values,
+ &disposition,
+ &actual_attr,
+ 0, &buffer_flags) != 0) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "referred_r: entry \"%s\" has no "
+ "values for \"%s\"\n",
+ slapi_sdn_get_dn(sdn),
+ cbdata->attribute);
+ } else {
+ /* Walk the value set. */
+ for (i = slapi_valueset_first_value(values, &value);
+ i != -1;
+ i = slapi_valueset_next_value(values, i, &value)){
+ /* Get the value. */
+ bval = slapi_value_get_berval(value);
+ /* If the value is empty, skip it. */
+ if (bval->bv_len == 0) {
+ continue;
+ }
+ format_add_bv_list(cbdata->choices, bval);
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "referred_r: found value "
+ "\"%.*s\" in \"%s\"\n",
+ bval->bv_len,
+ bval->bv_val,
+ slapi_sdn_get_dn(sdn));
+ }
+ slapi_vattr_values_free(&values, &actual_attr,
+ buffer_flags);
+ }
+ }
return 0;
}
@@ -1382,11 +1431,11 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
Slapi_Value *value;
struct berval **choices;
const struct berval *bval;
- struct format_note_entry_sdn_cbdata note_cbdata;
+ struct format_referred_r_entry_cbdata entry_cbdata;
struct format_ref_attr_list *list;
- char **argv, *attrs[2], *filter, *tndn, *attr, *other_attr;
+ char **argv, *attrs[2], *filter, *tndn, *attr;
char *actual_attr;
- char *other_set, *set_filter, **set_bases, *use_filter;
+ char *set_filter, **set_bases, *use_filter;
const char **attr_links, *ndn;
ret = format_parse_args(state, args, &argc, &argv);
@@ -1415,9 +1464,7 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
format_free_parsed_args(argv);
return -EINVAL;
}
- other_set = argv[0];
- other_attr = argv[1];
- attr = argv[2];
+ attr = argv[argc - 1];
/* Build the list of attributes which we can use to select the list of
* references. */
@@ -1479,8 +1526,10 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
* this point in the chain. */
these_entries = NULL;
format_add_sdn_list(&these_entries, slapi_entry_get_dn(e));
+ choices = NULL;
next_entries = NULL;
- attrs[0] = NULL;
+ attrs[0] = attr;
+ attrs[1] = NULL;
for (i = 0; i < list->n_links - 1; i++) {
these_bases = list->links[i].base_sdn_list;
if (i < list->n_links - 1) {
@@ -1515,7 +1564,7 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
slapi_log_error(SLAPI_LOG_PLUGIN,
state->plugin_desc->spd_id,
"referred_r: searching under %s"
- " for \"%s\" (link=%d.1)\n",
+ " for \"%s\" (link=1.%d)\n",
ndn, filter, i);
slapi_search_internal_set_pb(local_pb,
ndn,
@@ -1525,12 +1574,14 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
NULL, NULL,
state->plugin_identity,
0);
- note_cbdata.state = state;
- note_cbdata.sdn_list = &these_entries;
+ entry_cbdata.state = state;
+ entry_cbdata.attribute = attr;
+ entry_cbdata.choices = &choices;
+ entry_cbdata.sdn_list = &these_entries;
slapi_search_internal_callback_pb(local_pb,
- &note_cbdata,
+ &entry_cbdata,
NULL,
- format_note_entry_sdn_cb,
+ format_referred_r_entry_cb,
NULL);
}
free(filter);
@@ -1551,7 +1602,7 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
slapi_log_error(SLAPI_LOG_PLUGIN,
state->plugin_desc->spd_id,
"referred_r: searching under %s"
- " for \"%s\" (link=%d.2)\n",
+ " for \"%s\" (link=2.%d)\n",
ndn, filter, i);
slapi_search_internal_set_pb(local_pb,
ndn,
@@ -1561,12 +1612,14 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
NULL, NULL,
state->plugin_identity,
0);
- note_cbdata.state = state;
- note_cbdata.sdn_list = &next_entries;
+ entry_cbdata.state = state;
+ entry_cbdata.attribute = attr;
+ entry_cbdata.choices = &choices;
+ entry_cbdata.sdn_list = &next_entries;
slapi_search_internal_callback_pb(local_pb,
- &note_cbdata,
+ &entry_cbdata,
NULL,
- format_note_entry_sdn_cb,
+ format_referred_r_entry_cb,
NULL);
}
free(filter);
@@ -1577,73 +1630,7 @@ format_referred_r(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
these_entries = next_entries;
next_entries = NULL;
}
-
- /* Walk the list of entries at which we've finally arrived, and
- * extract the last attribute's value. */
- attrs[0] = list->links[list->n_links - 1].attribute;
- attrs[1] = NULL;
- choices = NULL;
- for (i = 0;
- (these_entries != NULL) && (these_entries[i] != NULL);
- i++) {
- next_entries = list->links[list->n_links - 1].base_sdn_list;
- ndn = slapi_sdn_get_ndn(these_entries[i]);
- format_add_sdn_list(&next_entries, slapi_dn_parent(ndn));
- list->links[list->n_links - 1].base_sdn_list = next_entries;
- /* Read the entry. */
- wrap_search_internal_get_entry(these_entries[i], attrs, &entry,
- state->plugin_identity);
- if (entry == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "referred_r: error reading entry "
- "\"%s\"\n",
- slapi_sdn_get_dn(these_entries[i]));
- continue;
- } else {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "referred_r: reading \"%s\" from entry "
- "\"%s\"\n", attrs[0],
- slapi_sdn_get_dn(these_entries[i]));
- }
- /* Pull up the value set. */
- if (slapi_vattr_values_get(entry, attrs[0], &values,
- &disposition,
- &actual_attr,
- 0, &buffer_flags) != 0) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "referred_r: entry \"%s\" has no "
- "values for \"%s\"\n",
- slapi_sdn_get_dn(these_entries[i]),
- attrs[0]);
- slapi_entry_free(entry);
- continue;
- }
- /* Walk the value set. */
- for (j = slapi_valueset_first_value(values, &value);
- j != -1;
- j = slapi_valueset_next_value(values, j, &value)){
- /* Get the value. */
- bval = slapi_value_get_berval(value);
- /* If the value is empty, skip it. */
- if (bval->bv_len == 0) {
- continue;
- }
- format_add_bv_list(&choices, bval);
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "referred_r: found value "
- "\"%.*s\" in \"%s\"\n",
- bval->bv_len,
- bval->bv_val,
- slapi_sdn_get_dn(these_entries[i]));
- }
- slapi_vattr_values_free(&values, &actual_attr,
- buffer_flags);
- slapi_entry_free(entry);
- }
+ format_free_sdn_list(these_entries);
/* Return any values we found. */
if (choices != NULL) {