The indexer factory function takes a parameter block from Directory Server. The function sets parameters such that Directory Server can update an index or sort results based on a matching rule.
The following figure shows how Directory Server uses the indexer factory function.
The following example shows the indexer factory function for the case exact matching rule.
#include "slapi-plugin.h" #define PLG_OID "1.3.6.1.4.1.42.2.27.999.4.1" #define SUBSYS "CaseExactMatching Plugin" /* Functions to obtain connection information for logging. */ static long mypblock_get_msgid( Slapi_PBlock * pb); static int mypblock_get_connid(Slapi_PBlock * pb); static int mypblock_get_opid( Slapi_PBlock * pb); static int plg_indexer_create(Slapi_PBlock * pb) { int rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* Init failed*/ char * mr_oid = NULL; /* MR OID from the server */ if (slapi_pblock_get(pb, SLAPI_PLUGIN_MR_OID, mr_oid) || (mr_oid == NULL)) { slapi_log_error_ex( -1, /* errorId */ mypblock_get_msgid(pb), mypblock_get_connid(pb), mypblock_get_opid(pb), SUBSYS, SLAPI_INTERNAL_ERROR, "plg_indexer_create failed: NULL OID values are invalid.\n" ); } else if (strcmp(mr_oid, PLG_OID) == 0) { if ( /* The MR OID from the server is handled by this plug-in. */ (slapi_pblock_set( /* This is for completeness. */ pb, /* Your plug-in may set a */ SLAPI_PLUGIN_MR_OID, /* different OID than the one */ PLG_OID /* provided by the server. */ ) == 0) && (slapi_pblock_set( /* Provide an appropriate */ pb, /* indexer function pointer. */ SLAPI_PLUGIN_MR_INDEX_FN, (void *)plg_index_entry ) == 0) && (slapi_pblock_set( /* Set the object destructor. */ pb, SLAPI_PLUGIN_DESTROY_FN, (void *)plg_filter_destroy ) == 0)) { rc = LDAP_SUCCESS; } else { slapi_log_error_ex( -1, /* errorId */ mypblock_get_msgid(pb), mypblock_get_connid(pb), mypblock_get_opid(pb), SUBSYS, SLAPI_INTERNAL_ERROR, "plg_indexer_create failed %d \n", rc ); } } return rc; }
Here, PLG_OID is the object identifier for the matching rule. plg_index_entry() is the indexer. plg_filter_destroy() is the destructor. Notice that the function returns LDAP_UNAVAILABLE_CRITICAL_EXTENSION on failure.
An indexer factory function can read the values for the following from the parameter block:
SLAPI_PLUGIN_MR_OID
SLAPI_PLUGIN_MR_TYPE
SLAPI_PLUGIN_MR_USAGE, indicates whether results must be sorted
SLAPI_PLUGIN_PRIVATE, if your plug-in uses private data that you specify in the plug-in initialization function
An indexer factory function should set values for at least the following in the parameter block before returning control to Directory Server:
SLAPI_PLUGIN_DESTROY_FN, a pointer to the indexer object destructor
SLAPI_PLUGIN_MR_INDEX_FN, a pointer to the indexer
SLAPI_PLUGIN_OBJECT, a pointer to the indexer object
Refer to Chapter 18, Parameter Block Reference for details about the parameter block.
This function must be thread safe. Directory Server can call this function concurrently.