The filter index function takes a parameter block from Directory Server. The function also sets pointers in the parameter block, enabling the server to read the index.
This example shows the filter index function for the case exact matching rule where the keys are the same as the values.
#include "slapi-plugin.h" #define PLG_OID "1.3.6.1.4.1.42.2.27.999.4.1" #define SUBSYS "CaseExactMatching Plugin" 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_filter_index(Slapi_PBlock * pb) { int rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION; void * obj = NULL; /* Server lets the plug-in */ plg_filter_t * fobj; /* handle the object type. */ int query_op = SLAPI_OP_EQUAL; /* Only exact matches */ if (!slapi_pblock_get(pb, SLAPI_PLUGIN_OBJECT, &obj)) { fobj = (plg_filter_t *)obj; /* Case exact match requires no modifications to * the at this point. Your plug-in may however * modify the object, then set it again in the * parameter block. */ rc = slapi_pblock_set( /* This is for completeness. */ pb, /* Your plug-in may modify */ SLAPI_PLUGIN_OBJECT, /* the object if necessary. */ fobj ); rc |= slapi_pblock_set( /* Set attr type to match. */ pb, SLAPI_PLUGIN_MR_TYPE, fobj->f_type ); rc |= slapi_pblock_set( /* Set fcn to obtain keys. */ pb, SLAPI_PLUGIN_MR_INDEX_FN, (void*)plg_index_entry ); rc |= slapi_pblock_set( /* Set values to obtain keys. */ pb, SLAPI_PLUGIN_MR_VALUES, fobj->f_values ); rc |= slapi_pblock_set( /* This is for completeness. */ pb, /* Your plug-in may set a */ SLAPI_PLUGIN_MR_OID, /* different MR OID than the */ PLG_OID /* one in the parameter block */ ); rc |= slapi_pblock_set( /* <, <=, ==, >=, >, substr */ pb, /* In this case, == */ SLAPI_PLUGIN_MR_QUERY_OPERATOR, &query_op ); } return rc; }
This code uses the variables and macros that follow:
fobj->ftype indicates the attribute type that is specified in the filter.
plg_index_entry() indicates the indexer function for generating keys from values.
fobj->values points to the berval array of attribute values.
PLG_OID is the object identifier of the matching rule.
query_op indicates the query operator from the filter.
A filter index function can get a pointer to the filter object from SLAPI_PLUGIN_OBJECT in the parameter block.
A filter index function should set values for at least the following in the parameter block before returning control to Directory Server:
SLAPI_PLUGIN_MR_INDEX_FN, the pointer to the indexer for generating the keys
SLAPI_PLUGIN_MR_OID
SLAPI_PLUGIN_MR_QUERY_OPERATOR
SLAPI_PLUGIN_MR_TYPE
SLAPI_PLUGIN_MR_VALUES
SLAPI_PLUGIN_OBJECT, if modified by your function
Refer to Chapter 18, Parameter Block Reference for details.
Directory Server never calls a filter index function for the same filter object concurrently. Directory Server can, however, call the function concurrently for different filter objects. If you use global variables, ensure that your function handles such variables safely.