This chapter explains how to write plug-in functions that handle matching rules.
Matching rule plug-in functions are described in the following sections:
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").
LDAPv3 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 sn attribute "sounds like" melon.)
An extensible match filter contains the following information:
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 mail attribute "sounds like" 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 uid attribute sounds like moxie.
Although the LDAPv3 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 to search the attributes in the DN as well. For example, if the OID 1.2.3.4 specifies a "sound-alike" match and if the string representation of the search filter is
then the client wants to find all entries in which the value of the sn attribute or the attributes in the DN (for example, uid, cn, ou, or o) sound like moxie.
Directory Serveralready includes 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.
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.
The matching rule plug-in consists of the following:
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.
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:
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.
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_EXTENSION
error back to the client.
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:
At some point in time, the server may also call the indexer destructor function (specified in the SLAPI_PLUGIN_MR_DESTROY_FN parameter) to free the indexer object that was created by the indexer factory function.
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:
Information specified in the filter object is used by both the filter index function and the filter matching function.
The server uses parameter blocks as a means to pass information to and from plug-in functions.
When calling your matching rule plug-in functions, the server will create a new Slapi_PBlock parameter 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. 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.
This section explains how to set up the server to index entries using a matching rule. The following topics are covered:
You also need to define an initialization function to register your indexer factory function.
When the server encounters a matching rule OID in an index directive 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_OID parameter 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.
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:
When the server is done, it frees any parameter blocks that were allocated during this process.
The indexer factory function takes a single Slapi_PBlock argument. This function should be thread-safe. The server may call this function concurrently.
The indexer factory function should do the following:
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 an Indexer Factory Function
|
Input parameter. Matching rule OID (if any) specified in the index directive. |
||
|
Input parameter. Attribute type (if any) specified in the index directive. |
||
|
Input parameter. Specifies the intended use of the indexer object. This parameter can have one of the following values:
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_PBlock argument. 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:
The server adds or removes the keys and the corresponding values from the appropriate indexes.
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 berval structures 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_VALUES parameter. The server creates indexes using these keys. |
This section explains how to set up the server to process searches that use extensible match filters (matching rules). The following topics are covered:
You also need to define an initialization function to register your filter factory function.
When the server processes a search request that has an extensible match filter, the server does the following:
As mentioned in How the Server Handles the Filter, the server uses a query operator when searching the index for possible candidates.
This applies to the ldbm default backend database. If you are using your own backend 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_OPERATOR
parameter 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
The filter factory function takes a single Slapi_PBlock argument. 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:
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 |
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. |
The filter index function takes a single Slapi_PBlock argument. 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:
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_VALUES and SLAPI_PLUGIN_MR_INDEX_FN against 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 berval structures 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. |
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:
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:
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:
The server calls the destructor function to free any memory that you've allocated; for example, to the indexer object or the filter object.
The destructor function takes a single Slapi_PBlock
argument. 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_OBJECT parameter 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.)
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_PBlock argument. The function should set the following parameters:
You need to register the initialization function so that the server runs the function when starting up. For how to register matching rule functions, see Registering Matching Rule Functions.
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
Depending on the Directory Server version, add the appropriate information for your plug-in function.
In current releases of Directory Server, shut down the server, add the plug-in parameters to the dse.ldif file, 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.conf
In Netscape Directory Server 4.x, add this directive to the slapd.ldbm.conf file:
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 named my_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
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_PBlock argument.
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 plugin directives appear in the server configuration file.
| Previous |
Contents |
Index |
DocHome | Next |