An indexer function takes a parameter block from Directory Server that contains a pointer to a berval array of attribute values. The function then generates a berval array of corresponding keys from the values. Finally, the function sets a pointer in the parameter block to the keys.
The following figure shows how Directory Server uses the indexer function.
The following example shows the indexer function for the case exact matching rule where the keys are the same as the values.
#include "slapi-plugin.h" typedef struct plg_filter_t /* For manipulating filter obj. */ { char * f_type; /* Attribute type to match */ int f_op; /* Type of comparison * (<, <=, ==, >=, >, substr) * for the filter. */ struct berval ** f_values; /* Array of values to match */ } plg_filter_t; static int plg_index_entry(Slapi_PBlock * pb) { int rc = LDAP_OPERATIONS_ERROR; void * obj = NULL; /* Server lets the plug-in */ plg_filter_t * fobj; /* handle the object type. */ struct berval ** values; /* Values from server */ if (slapi_pblock_get(pb, SLAPI_PLUGIN_OBJECT, &obj) == 0) { fobj = (plg_filter_t *)obj; if ( (slapi_pblock_get(pb, SLAPI_PLUGIN_MR_VALUES, &values) == 0) && (values != NULL) ) { /* The case exact match builds the index keys * from the values by copying the values because * the keys and values are the same. * * Your matching rule may do something quite * different before setting the keys associated * with the values in the parameter block. */ rc = slapi_pblock_set( /* Set keys based on values. */ pb, SLAPI_PLUGIN_MR_KEYS, slapi_ch_bvecdup(values) ); } } return rc; }
Here, obj points to the indexer object, and values points to the berval array of attribute values. Notice that the function returns LDAP_OPERATIONS_ERROR on failure. Technically, LDAP_OPERATIONS_ERROR indicates bad sequencing of LDAP operations. For historical reasons, the error is used in this context to indicate an internal error.
An indexer function can get values for the following from the parameter block:
SLAPI_PLUGIN_MR_VALUES
SLAPI_PLUGIN_MR_OBJECT
An indexer function should generate the berval array of keys. The function should set SLAPI_PLUGIN_MR_KEYS in the parameter block before returning control to Directory Server. Refer to Part II, Directory Server Plug-In API Reference for details.
Directory Server never calls an indexer for the same indexer object concurrently. Directory Server can, however, call the function concurrently for different indexer objects. If you use global variables, ensure that your function handles such variables safely.