|
||
|
|
Chapter 11 Writing Matching Rule Plug-Ins
This chapter explains how to write plug-in functions that handle matching rules.
Matching rule plug-in functions are described in the following sections:
- Understanding Matching Rules
![]()
- Understanding Matching Rule Plug-Ins
![]()
- Indexing Based on Matching Rules
![]()
- Handling Extensible Match Filters
![]()
- Writing a Destructor Function
![]()
- Writing an Initialization Function
![]()
- Registering Matching Rule Functions
![]()
- Specifying Start and Close Functions
![]()
A matching rule specifies how one or more attributes of a particular syntax should be compared against assertion values. For example, a matching rule that specifies a "sound-alike" comparison attempts to match values that sound like the specified value. Each matching rule is identified by a unique OID (for example, "1.2.3.4").
LDAP v3 clients can specify a matching rule as part of a search filter in a search request. This type of search filter is called an extensible match filter.
In an "extensible match" filter, the client specifies that it wants to use the matching rule to compare a specified value against the values of entries in the directory. (For example, an extensible match filter might find all entries in which the
snattribute "sounds like"melon.)An "extensible match" filter contains the following information:
- The OID of the matching rule or the attribute type that you want to search (or both)
![]()
- The value to search for
![]()
- A preference indicating whether or not to also search the attributes in the DN
![]()
For example, if the OID "1.2.3.4" identifies a matching rule that performs "sounds like" matches, the following extensible match filter attempts to find entries where the
moxie.In the search filter, the client can specify the OID (that identifies a matching rule) and the attribute type. This indicates that the value in the filter should be compared against the attribute using the matching rule.
For example, if the OID 1.2.3.4 specifies a "sound-alike" match and if the string representation of the search filter is:
the client wants to find entries in which the value of the
uidattribute sounds likemoxie.Note that although the LDAP v3 standard allows clients to omit the OID or the attribute type, at this time, the Netscape Directory Server only supports extensible match filters that specify both the OID and attribute type.
The filter can also specify a preference indicating whether or not to also search the attributes in the DN. For example, if the OID 1.2.3.4 specifies a "sound-alike" match and if the string representation of the search filter is:
the client wants to find all entries in which the value of the
snattribute or the attributes in the DN (for example,uid,cn,ou, oro) sound likemoxie.Extensible Match Filters in the Directory Server
Directory Server 6.x and earlier versions already include support for certain matching rules (which are used to determine the collation order and operator for searches of international data).
You can enable the Directory Server to handle your own matching rules for extensible match searches by defining your own matching rules plug-ins and registering them with the server.
You can also build indexes to improve the performance of search operations that use extended match filters.
Understanding Matching Rule Plug-Ins
A matching rule plug-in can create filters that the server can use when handling extensible search filters. A matching rule plug-in can also create indexers to index entries for extensible searches.
Functions Defined in Matching Rule Plug-Ins
The matching rule plug-in consists of the following:
- An indexer function (optional)
![]()
- A filter function
![]()
- A filter function that uses the index to speed up searches (optional)
![]()
- A function to destroy a filter (optional)
![]()
- A function to destroy an indexer (optional)
![]()
- A factory function to create filters
![]()
- A factory function to create indexers (optional)
![]()
- A close function to clean up before server shutdown (optional)
![]()
- An initialization function to register the factory functions and the close function
![]()
When the server starts up and loads the matching rule plug-in, it calls the initialization function. In this function, you pass the server the pointers to the factory functions and the close function. The server calls these functions when needed (see How Matching Rules Are Identified and How the Server Associates Plug-Ins with OIDs for details).
How Matching Rules Are Identified
Matching rules are identified by OID. When the server encounters an OID in the following situations, it attempts to find the matching rule plug-in that handles the matching rule with that OID.
The server can encounter a matching rule OID in the following situations:
- When reading in the server configuration file, the server may encounter an index directive that specifies the OID of the matching rule. For example:
![]()
- index <attribute_name> <filter_type> <matching_rule_oid>
- If the OID is associated with a matching rule plug-in, the server adds this OID to the list of matching rule OIDs to use for indexing.
- For information on setting up the server to index based on matching rule, see Indexing Based on Matching Rules.
- The server may receive an LDAP search request with an "extensible match" filter specifying the OID of the matching rule. For example, a string representation of an "extensible match" filter might be:
![]()
- (sn:dn:1.2.3.4:=Jensen)
- (The search filter above specifies that the server should use the matching rule identified by the OID 1.2.3.4 to search for the value
Jensenin thesnattribute and in all attributes in the DN.)
- For information on setting up the server to handle extensible match filters, see Handling Extensible Match Filters.
- The server may receive an LDAP search request containing a sorting control, and the sorting control specifies the OID of the matching rule.
![]()
- For information on setting up the server to sort based on matching rules, see Handling Sorting by Matching Rules.
In all of these situations, the server uses the matching rule OID to find the plug-in responsible for handling the rule (see How the Server Associates Plug-Ins with OIDs for details).
How the Server Associates Plug-Ins with OIDs
When the server encounters the OID for a matching rule, it attempts to find the plug-in associated with that matching rule.
If no plug-in is associated with the matching rule, the server calls each matching rule plug-in to find one that handles the specified matching rule.
When the server finds a plug-in that handles the matching rule, the server creates an association between the plug-in and the matching rule OID for future reference.
If no matching rule plug-in supports the specified OID, the server returns an
LDAP_UNAVAILABLE_CRITICAL_EXTENSIONerror back to the client.Finding a Plug-In for Indexing
To determine which matching rule plug-in is responsible for indexing an attribute with a given matching rule (based on its OID), the server does the following for each plug-in:
- In a new
Slapi_PBlockparameter block, the server sets the OID in theSLAPI_PLUGIN_MR_OIDparameter.![]()
- Next, the server calls the indexer factory function (specified in the
SLAPI_PLUGIN_MR_INDEXER_CREATE_FNparameter) for the plug-in.![]()
- The server checks the
SLAPI_PLUGIN_MR_INDEX_FNparameter.![]()
- If the parameter is NULL, the plug-in does not handle the matching rule specified by that OID.
![]()
- If the parameter returns an indexer function, this plug-in handles the matching rule specified by that OID.
![]()
- Finally, the server frees the parameter block from memory.
![]()
At some point in time, the server may also call the indexer destructor function (specified in the
SLAPI_PLUGIN_MR_DESTROY_FNparameter) to free the indexer object that was created by the indexer factory function.Finding a Plug-In for Searching
To determine which matching rule plug-in is responsible for handling an extensible match filter for a given matching rule (based on its OID), the server does the following for each plug-in:
- In a new
Slapi_PBlockparameter block, the server sets the following parameters:![]()
- Sets the OID in the
SLAPI_PLUGIN_MR_OIDparameter.![]()
- Sets the type (from the filter) in the
SLAPI_PLUGIN_MR_TYPEparameter.![]()
- Sets the value (from the filter) in the
SLAPI_PLUGIN_MR_VALUEparameter.![]()
- Next, the server calls the filter factory function (specified in the
SLAPI_PLUGIN_MR_FILTER_CREATE_FNparameter) for the plug-in.![]()
- The server checks the
SLAPI_PLUGIN_MR_FILTER_MATCH_FNparameter.![]()
- If the parameter is NULL, the plug-in does not handle the matching rule specified by that OID.
![]()
- If the parameter returns a filter matching function, this plug-in handles the matching rule specified by that OID.
![]()
- Finally, the server gets the following information from the plug-in for future use:
![]()
- The filter index function specified in the
SLAPI_PLUGIN_MR_FILTER_INDEX_FNparameter![]()
- The value specified in the
SLAPI_PLUGIN_MR_FILTER_REUSABLEparameter![]()
- The filter reset function specified in the
SLAPI_PLUGIN_MR_FILTER_RESET_FNparameter![]()
- The filter object specified in the
SLAPI_PLUGIN_OBJECTparameter![]()
- The filter destructor function specified in the
SLAPI_PLUGIN_DESTROY_FNparameter![]()
Information specified in the filter object is used by both the filter index function and the filter matching function.
How the Server Uses Parameter Blocks
The server uses parameter blocks as a means to pass information to and from your plug-in functions.
When calling your matching rule plug-in functions, the server will create a new
Slapi_PBlockparameter block, set some input parameters, and pass the parameter block to your function. After retrieving output parameters from the block, the server typically frees the parameter block from memory.In general, you should not expect a parameter block to be passed from plug-in function to plug-in function. For example, the value of a parameter set by one plug-in function may not necessarily be accessible to other plug-in functions, since each function is usually passed a new and different parameter block.
Indexing Based on Matching Rules
This section explains how to set up the server to index entries using a matching rule. The following topics are covered:
- How the Server Sets Up the Index
![]()
- How the Server Updates the Index
![]()
- Writing the Indexer Factory Function
![]()
- Getting and Setting Parameters in Indexer Factory Functions
![]()
- Writing the Indexer Function
![]()
- Writing the Indexer Function
![]()
Note that you also need to define an initialization function to register your indexer factory function.
How the Server Sets Up the Index
When the server encounters a matching rule OID in an
indexdirective in the server configuration file, the server determines which plug-in supports the matching rule identified by the OID. See How the Server Associates Plug-Ins with OIDs for details.The server gets the OID returned in the
SLAPI_PLUGIN_MR_OIDparameter and associates this OID with the rest of the attribute indexing information (such as the attribute type and the type of index) for future reference.When adding, modifying, or deleting the values of an attribute, the server will check this information to determine if the attribute is indexed. See How the Server Updates the Index for information on how attributes are indexed.
How the Server Updates the Index
When a value is added, modified, or removed from an attribute in an entry (or when the RDN of an entry is changed), the server does the following if that attribute has an index that uses matching rules:
- In a new
Slapi_PBlockparameter block, the server sets the following parameters:![]()
- Sets the OID in the
SLAPI_PLUGIN_MR_OIDparameter.![]()
- Sets the attribute type (of the value being added, modified, or removed) in the
SLAPI_PLUGIN_MR_TYPEparameter.![]()
- Next, the server calls the indexer factory function (specified in the
SLAPI_PLUGIN_MR_INDEXER_CREATE_FNparameter) for the plug-in to create the indexer object.![]()
- The server generates the index keys for the values to be added or deleted:
![]()
- The server first verifies that the
SLAPI_PLUGIN_MR_INDEX_FNparameter specifies an indexer function and theSLAPI_PLUGIN_MR_OIDparameter specifies the official OID of the matching rule.![]()
- If these are both set, the server sets the
SLAPI_PLUGIN_MR_VALUESparameter to the array ofbervalstructures containing the new or modified values that need to be indexed and calls the indexer function.![]()
- Next, the server gets the value of the
SLAPI_PLUGIN_MR_KEYSparameter, which is an array ofbervalstructures containing the keys corresponding to the values.![]()
- The server inserts or deletes the keys and values in the index for that attribute.
![]()
- The server calls the indexer destructor function (specified in the
SLAPI_PLUGIN_MR_DESTROY_FNparameter) to free the indexer object.![]()
When the server is done, it frees any parameter blocks that were allocated during this process.
Writing the Indexer Factory Function
The indexer factory function takes a single
Slapi_PBlockargument. This function should be thread-safe. The server may call this function concurrently.The indexer factory function should do the following:
- Get the OID from the
SLAPI_PLUGIN_MR_OIDparameter and determine whether or not that OID is supported by your plug-in.![]()
- If the OID is not supported, you need to return the result code
LDAP_UNAVAILABLE_CRITICAL_EXTENSION.![]()
- If the OID is supported, continue with this process.
![]()
- Get the value of the
SLAPI_PLUGIN_MR_USAGEparameter. This parameter should have one of the following values:![]()
- If the value is
SLAPI_PLUGIN_MR_USAGE_SORT, the server is calling your function to sort search results. See Handling Sorting by Matching Rules for more information.![]()
- If the value is
SLAPI_PLUGIN_MR_USAGE_INDEX, the server is calling your function to index an entry.![]()
- You can use this information to set different information in the indexer object or to set a different indexer function, based on whether the function is being called to index or to sort.
- You can also get any data that you set in the
SLAPI_PLUGIN_PRIVATEparameter during initialization. (See Writing an Initialization Function.)![]()
- Create an indexer object containing any information that you want passed to the indexer function.
![]()
- Set the following parameters:
![]()
- Set the
SLAPI_PLUGIN_MR_OIDparameter to the official OID of the matching rule (if the value of that parameter is not the official OID).![]()
- Set the
SLAPI_PLUGIN_OBJECTparameter to the indexer object.![]()
- Set the
SLAPI_PLUGIN_MR_INDEX_FNparameter to the indexer function. (See Writing the Indexer Function.)![]()
- Set the
SLAPI_PLUGIN_DESTROY_FNparameter to the function responsible for freeing any memory allocated by the factory function, such as the indexer object. (See Writing a Destructor Function for details.)![]()
- Return 0 (or the result code
LDAP_SUCCESS) if everything completed successfully.![]()
Getting and Setting Parameters in Indexer Factory Functions
The following table summarizes the different parameters that the indexer factory function should get and set in the parameter block that is passed in:
Table 11-1 Input and Output Parameters Available to a Indexer Factory Function
(Input parameter) Matching rule OID (if any) specified in the
indexdirective.(Input parameter) Attribute type (if any) specified in the
indexdirective.(Input parameter) Specifies the intended use of the indexer object. This parameter can have one of the following values:
SLAPI_PLUGIN_MR_USAGE_INDEXspecifies that the indexer object should be used to index entries.![]()
SLAPI_PLUGIN_MR_USAGE_SORTspecifies that the indexer object should be used to sort entries.![]()
You can use this to specify different information in the indexer object or different indexer functions, based on whether the plug-in is used for indexing or sorting.
For information on sorting search results, see Handling Sorting by Matching Rules.
(Input parameter) Pointer to any private data originally specified in the initialization function. (See Writing an Initialization Function for details.)
(Output parameter) Name of the function called by the server to generate a list of keys used for indexing a set of values.
(Output parameter) Name of the function to be called to free the indexer object.
(Output parameter) Pointer to the indexer object created by your factory function.
The indexer function takes a single
Slapi_PBlockargument. This function will never be called for the same indexer object concurrently. (If you plan to manipulate global variables, keep in mind that the server can call this function concurrently for different indexer objects.)The indexer function should do the following:
- Get the values of the following parameters:
![]()
- Get the indexer object from the
SLAPI_PLUGIN_OBJECTparameter (if the parameter is set).![]()
- Get the array of values that you want indexed from the
SLAPI_PLUGIN_MR_VALUESparameter.![]()
- Generate index keys for these values, and set the
SLAPI_PLUGIN_MR_KEYSparameter to the array of these keys.![]()
- Return 0 (or the result code
LDAP_SUCCESS) if everything completed successfully.![]()
The server adds or removes the keys and the corresponding values from the appropriate indexes.
Getting and Setting Parameters in Indexer Functions
The following table summarizes the different parameters that the indexer function should get and set in the parameter block that is passed in:
Table 11-2 Input and output parameters available to an indexer function
(Input parameter) Pointer to an array of
bervalstructures containing the values of the entry's attributes that need to be indexed.(Input parameter) Pointer to the indexer object created by the indexer factory function. (See Writing the Indexer Factory Function for details.)
(Output parameter) Keys generated for the values specified in the
SLAPI_PLUGIN_MR_VALUESparameter. The server creates indexes using these keys.
Handling Extensible Match Filters
This section explains how to set up the server to process searches that use extensible match filters (matching rules). The following topics are covered:
- How the Server Handles the Filter
![]()
- Writing a Filter Factory Function
![]()
- Writing a Filter Index Function
![]()
- Writing a Filter Matching Function
![]()
Note that you also need to define an initialization function to register your filter factory function.
How the Server Handles the Filter
When the server processes a search request that has an extensible match filter, the server does the following:
- First, the server finds the plug-in associated with this OID, if an association between the OID and plug-in has already been made.
![]()
- If no association has been made yet, the server attempts to find a matching rule plug-in that handles the OID. (See How the Server Associates Plug-Ins with OIDs for details.)
- Next, the server attempts to generate a list of search result candidate from the indexes. In a new
Slapi_PBlockparameter block, the server does the following:![]()
- The server puts the filter object in the
SLAPI_PLUGIN_OBJECTparameter, and calls the filter index function (specified in theSLAPI_PLUGIN_MR_FILTER_INDEX_FNparameter).![]()
- The server checks the value of the
SLAPI_PLUGIN_MR_QUERY_OPERATORparameter. If the operator is an known type (such asSLAPI_OP_EQUAL), the server will use the operator when searching the index for candidates. (For details, see Query Operators in Matching Rules).![]()
- The server sets the
SLAPI_PLUGIN_MR_VALUESparameter to each of the values specified in the filter and calls the indexer function (which is specified in theSLAPI_PLUGIN_MR_INDEX_FNparameter) to generate the key (specified in theSLAPI_PLUGIN_MR_KEYSparameter).![]()
- The server uses the keys and the query operator to find potential candidates in the indexes.
![]()
- The server considers all entries to be potential candidates if at least one of the following is true:
- The matching rule plug-in has no indexer function (specified in the
SLAPI_PLUGIN_MR_INDEX_FNparameter).![]()
- No index applies to the search (for example, if the query operator does not correspond to an index).
![]()
- No keys are generated for the specified values.
![]()
- For each candidate entry, the server checks to see if the entry matches the search filter by doing the following:
![]()
- The server calls the filter matching function (which is specified in the
SLAPI_PLUGIN_MR_FILTER_MATCH_FNparameter), passing in the filter object, the entry, and the attributes of the entry.![]()
- If the entry does not match but the search request also specifies that the attributes in the DN should be searched, the server calls the filter matching function again, passing in the filter object, the entry, and the attributes in the DN.
![]()
- The server checks the value returned by the filter matching function:
- If the function returns 0, the entry matched the search filter.
![]()
- If the function returns -1, the entry did not match the search filter.
![]()
- If the function returns an LDAP error code (a positive value), an error occurred.
![]()
- If the entry matches the filter, the server verifies that the entry is in the scope of the search before returning the entry to the LDAP client as a search result.
![]()
Query Operators in Matching Rules
As mentioned in How the Server Handles the Filter, the server uses a query operator when searching the index for possible candidates.
Note that this applies to the
ldbmdefault back-end database. If you are using your own back-end or if you have not set up indexing by matching rules, the server does not make use of the query operator.The server checks the value of the
SLAPI_PLUGIN_MR_QUERY_OPERATORparameter to determine which operator is specified. The following table lists the possible values for this parameter.
Table 11-3 Query Operators in Extensible Match Filters
If the query operator is
SLAPI_OP_EQUAL, the server attempts to find the keys in the index that match the value specified in the search filter. In the case of the other query operators, the server attempts to find ranges of keys that match the value.Writing a Filter Factory Function
The filter factory function takes a single
Slapi_PBlockargument. This function should be thread-safe. The server may call this function concurrently. (Each incoming LDAP request is handled by a separate thread. Multiple threads may call this function if processing multiple requests that have extensible match filters.)The filter factory function should do the following:
- Get the OID from the
SLAPI_PLUGIN_MR_OIDparameter and determine whether or not that OID is supported by your plug-in.![]()
- If the OID is not supported, you need to return the result code
LDAP_UNAVAILABLE_CRITICAL_EXTENSION. The server will send this back to the client.![]()
- If the OID is supported, continue with this process.
![]()
- Get and check the values of the
SLAPI_PLUGIN_MR_TYPEandSLAPI_PLUGIN_MR_VALUEparameters.![]()
- The values of these parameters are the attribute type and value specified in the extensible match filter.
- You can also get any data that you set in the
SLAPI_PLUGIN_PRIVATEparameter during initialization. (See Writing an Initialization Function.)![]()
- Create a filter object, putting the following information in the object:
![]()
- The official OID of the matching rule (optional)
![]()
- The attribute type specified in the filter
![]()
- The value specified in the filter
![]()
- Any additional data that you want made available to the filter index function (for example, the query operator, if specified in the filter)
![]()
- The server will call your filter index function at a later time to extract this information from the filter object.
- Set the following parameters:
![]()
- Set the
SLAPI_PLUGIN_MR_OIDparameter to the official OID of the matching rule, if the value of that parameter is not the official OID (optional).![]()
- Set the
SLAPI_PLUGIN_OBJECTparameter to the filter object.![]()
- Set the
SLAPI_PLUGIN_MR_FILTER_INDEX_FNparameter to the filter index function (see Writing a Filter Index Function), if you have set up indexes based on this matching rule (optional).![]()
- Set the
SLAPI_PLUGIN_MR_FILTER_MATCH_FNparameter to the filter matching function. (See Writing a Filter Matching Function.)![]()
- Set the
SLAPI_PLUGIN_DESTROY_FNparameter to the function responsible for freeing the filter object, if you have defined this function (optional). See Writing a Destructor Function for details.![]()
- Return 0 (or the result code
LDAP_SUCCESS) if everything completed successfully.![]()
Getting and Setting Parameters in Filter Factory Functions
The following table summarizes the different parameters that the filter factory function should get and set in the parameter block that is passed in:
Table 11-4 Input and Output Parameters Available to a Filter Factory Function
(Input parameter) Matching rule OID (if any) specified in the extensible match filter.
(Input parameter) Attribute type (if any) specified in the extensible match filter.
(Input parameter) Value specified in the extensible match filter.
(Input parameter) Pointer to any private data originally specified in the initialization function. (See Writing an Initialization Function for details.)
mrFilterMatchFn
(function pointer)(Output parameter) Name of the function called by the server to match an entry's attribute values against the value in the extensible search filter.
(Output parameter) Name of the function called by the server to generate a list of keys used for indexing a set of values.
(Output parameter) Name of the function to be called to free the filter object.
(Output parameter) Pointer to the filter object created by your factory function.
Writing a Filter Index Function
The filter index function takes a single
Slapi_PBlockargument. This function will never be called for the same filter object concurrently. (If you plan to manipulate global variables, keep in mind that the server can call this function concurrently for different filter objects.)The filter index function should do the following:
- Get the filter object from the
SLAPI_PLUGIN_OBJECTparameter (if the parameter is set).![]()
- Using data from the object, determine and set the values of the following parameters:
![]()
- Set the
SLAPI_PLUGIN_MR_OIDparameter to the official OID of the matching rule.![]()
- Set the
SLAPI_PLUGIN_MR_TYPEparameter to the attribute type in the filter object.![]()
- Set the
SLAPI_PLUGIN_MR_VALUESparameter to the values in the filter object.![]()
- Set the
SLAPI_PLUGIN_MR_QUERY_OPERATORparameter to the query operator that corresponds to this search filter. (See Query Operators in Matching Rules for possible values for this parameter.)![]()
- Set the
SLAPI_PLUGIN_OBJECTparameter to the filter object.![]()
- Set the
SLAPI_PLUGIN_MR_INDEX_FNparameter to the indexer function. (See Writing the Indexer Function.)![]()
- Return 0 (or the result code
LDAP_SUCCESS) if everything completed successfully.![]()
Getting and Setting Parameters in Filter Index Functions
The following table summarizes the different parameters that the filter index function should get and set in the parameter block that is passed in:
Table 11-5 Input and Output Parameters Available to a Filter Index Function
(Input and output parameter) Pointer to the filter object created by the factory function. (For details, see Writing a Filter Factory Function.)
(Output parameter) Query operator used by the server to determine how to compare the keys generated from
SLAPI_PLUGIN_MR_VALUESandSLAPI_PLUGIN_MR_INDEX_FNagainst keys in the index.For a list of possible values for this parameter, see Query Operators in Matching Rules.
(Output parameter) Official matching rule OID (if any) specified in the extensible match filter.
(Output parameter) Attribute type (if any) specified in the extensible match filter.
(Output parameter) Pointer to an array of
bervalstructures containing the values specified in the extensible match filter.(Output parameter) Name of the function called by the server to generate a list of keys used for indexing a set of values.
Writing a Filter Matching Function
The filter matching function has the following prototype:
#include "slapi-plugin.h"
typedef int (*mrFilterMatchFn) (void* filter,
Slapi_Entry* entry, Slapi_Attr* attrs);This function passes the following arguments:
filteris a pointer to the filter object.![]()
entryis a pointer to theSlapi_Entryentry that should be compared against the filter.![]()
attrsis the firstSlapi_Attrattribute in the entry or in the set of DN attributes. (The extensible match filter might specify that the attributes in the DN of an entry should also be included in the search.)![]()
This function will never be called for the same filter object concurrently. (If you plan to manipulate global variables, keep in mind that the server can call this function concurrently for different filter objects.)
The filter matching function should do the following:
- From the filter object, get the attribute type, the values, and the query operator.
![]()
- Find the corresponding attribute in the attributes passed into the function. Make sure to check for subtypes of an attribute (for example, "cn;lang-ja") in the filter and in the attributes specified by
attrs.![]()
- You can call the
slapi_attr_type_cmp()function to compare the attribute in the filter against the attributes passed in as arguments.
- Using the query operator to determine how the values should be compared, compare the values from the filter against the values from the values in the attribute.
![]()
- Return one of the following values:
![]()
Handling Sorting by Matching Rules
If you have set up indexing by a matching rule, you can also sort search results by that matching rule. The server can use the keys in the index to sort the search results.
When processing a request to sort by a matching rule, the server does the following:
- In a new
Slapi_PBlockparameter block, the server sets the following parameters:![]()
- Sets the OID in the
SLAPI_PLUGIN_MR_OIDparameter.![]()
- Sets the attribute type (of the value being added, modified, or removed) in the
SLAPI_PLUGIN_MR_TYPEparameter.![]()
- Sets the
SLAPI_PLUGIN_MR_USAGEparameter toSLAPI_PLUGIN_MR_USAGE_SORT. (This indicates that the created indexer object will be used for sorting, not indexing.)![]()
- Next, the server calls the indexer factory function (specified in the
SLAPI_PLUGIN_MR_INDEXER_CREATE_FNparameter) for the plug-in.![]()
- The server generates the index keys for the values to be sorted:
![]()
- The server sets the
SLAPI_PLUGIN_MR_VALUESparameter to the array ofbervalstructures containing the values to be sorted.![]()
- The server calls the indexer function (specified by the
SLAPI_PLUGIN_MR_INDEXER_FNparameter).![]()
- Next, the server gets the value of the
SLAPI_PLUGIN_MR_KEYSparameter, which is an array ofbervalstructures containing the keys corresponding to the values.![]()
- The server compares the keys to sort the results.
![]()
The server calls the destructor function to free any memory that you've allocated (for example, the indexer object or the filter object).
The destructor function takes a single
Slapi_PBlockargument. The following table summarizes the different parameters that the destructor function should get and set in the parameter block that is passed in:
Table 11-6 Input and Output Parameters Available to a Destructor Function
(Input parameter) Pointer to the filter object or indexer object created by your factory function.
For example, your destructor function can get the indexer object from the
SLAPI_PLUGIN_OBJECTparameter and free the object from memory.This function will never be called for the same indexer or filter object concurrently. (If you plan to manipulate global variables, keep in mind that the server can call this function concurrently for different filter or indexer objects.)
Writing an Initialization Function
Internally, the server keeps a list of matching rule plug-ins. When dealing with matching rules, the server attempts to find the matching rule plug-in to handle the given matching rule. (See How the Server Associates Plug-Ins with OIDs for details.)
In order to add your plug-in to that internal list, you need to write an initialization function. The initialization function takes a single
Slapi_PBlockargument. The function should set the following parameters:
- The
SLAPI_PLUGIN_MR_FILTER_CREATE_FNparameter should be set to the filter factory function. See How the Server Handles the Filter and Writing a Filter Factory Function for details.![]()
- The
SLAPI_PLUGIN_MR_INDEXER_CREATE_FNparameter should be set to the indexer factory function, if you have defined one (optional). See How the Server Sets Up the Index and Writing the Indexer Factory Function for details.![]()
- The
SLAPI_PLUGIN_CLOSE_FNparameter should be set to the "close" function, if you have defined one (optional). See Specifying Start and Close Functions for details.![]()
- The
SLAPI_PLUGIN_PRIVATEparameter should be set to any private data you want made accessible to the plug-in functions (optional).![]()
You need to register the initialization function (see Registering Matching Rule Functions) so that the server runs the function when starting up.
The following table summarizes the different parameters that the initialization function should get and set in the parameter block that is passed in:
Table 11-7 Input and Output Parameters Available to a Matching Rule Plug-In Initialization Function
Registering Matching Rule Functions
Depending on the Directory Server version, add the appropriate information for your plug-in function:
In Directory Server 6.x, shut down the server, add the plug-in parameters to the
dse.ldiffile, and restart the server (see Chapter 3 "Configuring Plug-Ins"). For example, your plug-in entry might look like this:
dn: cn=Test MatchineRule,cn=plugins,cn=config
objectClass: top
objectClass: nsSlapdPlugin
objectClass: extensibleObject
cn: Test MatchingRule
nsslapd-pluginPath: /usr/netscape/servers/slapd-host1/plugins/slapd/slapi/
examples/libtest-plugin.so
nsslapd-pluginInitfunc: testmatchrule_init
nsslapd-pluginType: matchingRule
nsslapd-pluginEnabled: on
nsslapd-pluginId: test-matchingrule
nsslapd-pluginarg0: /usr/netscape/servers/slapd-host1/
customplugins/filename.confIn Netscape Directory Server 4.x, add this directive to the
slapd.ldbm.conffile:plugin matchingrule [on|off] "<name of plugin>" \
<library_name> <init_fn_name> [<arguments>...]
<init_fn_name>is the name of your initialization function and<library_name>is the name and path of the library where the function is defined. For example, the following directive registers the initialization function namedmy_init_fn(), which is defined in the library/usr/ns/myplugin.so:plugin matchingrule on "my matching rule plugin" /usr/ns/myplugin.so my_init_fn
Specifying Start and Close Functions
For each matching rule operation plug-in, you can specify the name of a function to be called after the server starts and before the server is shut down. These functions take a single
Slapi_PBlockargument.The following table summarizes the different parameters that the initialization function should get and set in the parameter block that is passed in:
Table 11-8 Input and output parameters available to a matching rule plug-in initialization function
(Output parameter) The function called after the Directory Server starts up.
(Output parameter) The function called before the Directory Server shuts down.
If you register multiple plug-ins with different start and close functions, the functions are called in the order that the plug-ins are registered (in other words, in the order that the
plugindirectives appear in the server configuration file).
© 2001 Sun Microsystems, Inc. Portions copyright 1999, 2002 Netscape Communications Corporation. All rights reserved.
Last Updated August 23, 2002