|
||
|
|
Chapter 14 Data Type and Structure Reference
This chapter summarizes the data types and structures that you can use when writing Netscape Directory Server (Directory Server) plug-in functions.
Summary of Data Types and Structures
The functions in the server plug-in API use the following data types and structures:
Represents binary data that is encoded using simplified Basic Encoding Rules (BER).
typedef struct berval {
unsigned long bv_len;
char *bv_val;
}BerValue;This function has the following parameters:
The
bervaldata structure represents binary data that is encoded using simplified Basic Encoding Rules (BER). The data and size of the data are included in abervalstructure.Use a
bervalstructure when working with attributes that contain binary data (such as a JPEG or audio file).
Represents information used for a computed attribute.
typedef struct _computed_attr_context computed_attr_context;
computed_attr_contextis the data type for an opaque structure that represents information about a computed attribute.Before the Directory Server sends an entry back to a client, it determines if any of the attributes are computed, generates the attributes, and includes the generated attributes in the entry.
As part of this process, the server creates a
computed_attr_contextstructure to pass relevant information to the functions generating the attribute values. (Relevant information might include the attribute type, the BER-encoded request so far, and the parameter block).
Represents a client or server control associated with an LDAP operation.
typedef struct ldapcontrol {
char *ldctl_oid;
struct berval ldctl_value;
char ldctl_iscritical;
} LDAPControl;This function has the following parameters:
bervalstructure containing the value used by the control for the operation.Specifies whether or not the control is critical to the operation. This field can have one of the following values:
The
LDAPControldata type represents a client or server control associated with an LDAP operation. Controls are part of the LDAP v3 protocol. You can use a client or server control to extend the functionality of an LDAP control.For example, you can use a server control to specify that you want the server to sort search results in an LDAP search operation.
The following table summarizes the front-end API functions that you can call to work with LDAP controls.
Specifies changes to an attribute in an directory entry.
typedef struct ldapmod {
int mod_op;
char *mod_type;
union mod_vals_u{
char **modv_strvals;
struct berval **modv_bvals;
} mod_vals;
#define mod_values mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals
} LDAPMod;This function has the following parameters:
LDAPModis a type of structure that you use to specify changes to an attribute in an directory entry. Before you call theslapi_add_internal_pb()andslapi_modify_internal_pb()routines to add or modify an entry in the directory, you need to fillLDAPModstructures with the attribute values that you intend to add or change.The following section of code sets up an
LDAPModstructure to change the email address of a user's entry to "bab@example.com":
The following table summarizes the front-end API functions that you can call to specify changes to an attribute in an directory entry.
Retrieves the reference to the
LDAPModcontained in aSlapi_Modstructure
Slapi_Mod and Slapi_Mods.
Specifies the prototype for a filter matching callback function.#include "slapi-plugin.h"
typedef int (*mrFilterMatchFn) (void* filter,
Slapi_Entry* entry, Slapi_Attr* attrs);This function has the following parameters:
This function returns an integer value of 0 if the filter is matched or -1 if the filter did not match. If an LDAP error occurs, it returns a value >0.
mrFilterMatchFnspecifies the prototype for a filter matching function that is called by the server when processing an extensible match filter.An extensible match filter specifies either the OID of a matching rule or an attribute type (or both) that indicates how matching entries are found. For example, a sound-alike matching rule might find all entries that sound like a given value.
To handle an extensible match filter for a matching rule, you can write a matching rule plug-in.
You need to define the filter matching function, which is the function that has prototype specified by
mrFilterMatchFn. The server calls this function for each potential matching candidate entry. The server passes pointers to a filter structure (that you create in your filter factory function see "Writing a Filter Factory Function"), the candidate entry, and the entry's attributes.In your filter matching function, you can retrieve information about the filter (such as the attribute type and value specified in the filter) from the filter structure. You can then use this information to compare the value in the filter against the attribute values in the candidate entry.
For more information on writing a filter matching function, see "Writing a Filter Matching Function."
plugin_referral_entry_callback
This typedef is used for LDAP referral entry callback functions, which are plugin-defined functions that process LDAP references generated by some internal searches.
#include "slapi-plugin.h"
typedef int (*plugin_referral_entry_callback)
(char *referral, void *callback_data);The function takes the following parameters:
The URL of a reference that is returned in response to an internal search call.
This value matches the
callback_datapointer that was passed to the original internal operation function.
0 if successful or -1 if an error occurred.
A function that matches this typedef can be passed as the
precparameter ofslapi_search_internal_callback_pb(), or as theref_callbackparameter of theslapi_seq_internal_callback_pb()function.The LDAP referral entry callback function will be called once for each referral entry found by a search operation, which means it could be called 0 or any number of times.
The
callback_dataparameter can be used to pass arbitrary plug-in or operation-specific information to a referral entry callback function.
This typedef is used for LDAP result callback functions, which are plugin-defined functions that process result messages that are generated by some internal search functions.
#include "slapi-plugin.h"
typedef void (*plugin_result_callback)(int rc,
void *callback_data);The function takes the following parameters:
The LDAP result code of the internal operation, for example,
LDAP_SUCCESS.This value matches the
callback_datapointer that was passed to the original internal operation function.
0 if successful or -1 if an error occurred.
A function that matches this typedef can be passed as the
prcparameter ofslapi_search_internal_callback_pb(), or as theres_callbackparameter ofslapi_seq_internal_callback_pb().The LDAP result callback function should be called once for each search operation, unless the search is abandoned, in which case it will not be called.
The
callback_dataparameter can be used to pass arbitrary plug-in or operation-specific information to a result callback function.
This typedef is used for LDAP search entry callback functions, which are plug-in defined functions that process LDAP entries that are located by an internal search.
#include "slapi-plugin.h"
typedef int (*plugin_search_entry_callback)(Slapi_Entry *e,
void *callback_data);The function has the following parameters:
Pointer to the
Slapi_Entrystructure representing an entry found by the search.This value matches the
callback_datapointer that was passed to the original internal operation function.
0 if successful or -1 if an error occurred.
A function that matches this typedef can be passed as the
psecparameter ofslapi_search_internal_callback_pb(), or as thesrch_callbackparameter ofslapi_seq_internal_callback_pb().The LDAP referral entry callback function will be called once for each referral entry found by a search operation, which means it could be called 0 or any number of times.
The
callback_dataparameter can be used to pass arbitrary plug-in or operation-specific information to a referral entry callback function.
send_ldap_referral_fn_ptr_tspecifies the prototype for a callback function that you can write to send LDAP v3 referrals (search result references) back to the client. You can register your function so that it is called whenever theslapi_send_ldap_result()function is called.#include "slapi-plugin.h"
typedef int (*send_ldap_referral_fn_ptr_t)( Slapi_PBlock *pb,
Slapi_Entry *e, struct berval **refs, struct berval ***urls);The function has the following parameters:
0 if successful, or -1 if an error occurs.
The
slapi_send_ldap_result()function is responsible for sending LDAP v3 referrals (search result references) back to the client. You can replace the function that sends LDAP v3 referrals to the client with your own function. To do this:
- Write a function with the prototype specified by
send_ldap_result_fn_ptr_t.![]()
- In your plug-in initialization function, register your function by setting the
SLAPI_PLUGIN_PRE_REFERRAL_FNparameter in the parameter block to the name of your function if you are using the pre-operation plug-in. If your are using the post-operation plug-in, register your function by setting theSLAPI_PLUGIN_POST_REFERRAL_FNparameter in the parameter block to the name of your function.![]()
See
slapi_send_ldap_result()for information on the default function that sends LDAP v3 referrals to clients.
send_ldap_result_fn_ptr_tspecifies the prototype for a callback function that you can write to send LDAP result codes back to the client. You can register your function so that it is called whenever theslapi_send_ldap_result()function is called.#include "slapi-plugin.h"
typedef void (*send_ldap_result_fn_ptr_t)( Slapi_PBlock *pb,
int err, char *matched, char *text, int nentries,
struct berval **urls );The function has the following parameters:
The
slapi_send_ldap_result()function is responsible for sending LDAP result codes back to the client. You can replace the function that sends LDAP result codes to the client with your own function. To do this:
- Write a function with the prototype specified by
send_ldap_result_fn_ptr_t.![]()
- In your plug-in initialization function, register your function for sending results to the client by setting the
SLAPI_PLUGIN_PRE_RESULT_FNorSLAPI_PLUGIN_POST_RESULT_FNparameter (depending on the type of plug-in, and if it is a pre-operation or post-operation, respectively) in the parameter block to the name of your function.![]()
See
slapi_send_ldap_result()for information on the default function that sends LDAP result codes to clients.send_ldap_search_entry_fn_ptr_t
send_ldap_result_fn_ptr_tspecifies the prototype for a callback function that you can write to send search results (entries found by a search) back to the client. You can register your function so that it is called whenever theslapi_send_ldap_search_entry()function is called.#include "slapi-plugin.h"
typedef int (*send_ldap_search_entry_fn_ptr_t)
( Slapi_PBlock *pb, Slapi_Entry *e, LDAPControl **ectrls,
char **attrs, int attrsonly );The
slapi_send_ldap_search_entry()function is responsible for sending entries found by a search back to the client. You can replace the function that sends entries to the client with your own function. To do this:
- Write a function with the prototype specified by
send_ldap_search_entry_fn_ptr_t.![]()
- In your plug-in initialization function, register your function by setting the
SLAPI_PLUGIN_PRE_ENTRY_FNparameter in the parameter block to the name of your function if you are using the pre-operation plug-in. If you are using the post-operation plug-in, register your function by setting theSLAPI_PLUGIN_POST_ENTRY_FNparameter in the parameter block to the name of your function.![]()
See
slapi_send_ldap_search_entry()for information on the default function that sends entries to clients.
slapi_send_ldap_search_entry()
Represents an attribute in an entry.
#include slapi-plugin.h
typedef struct slapi_attr Slapi_Attr;
Slapi_Attris the data type for an opaque structure that represents an attribute in a directory entry. In certain cases, your server plug-in may need to work with an entry's attributes.The following table summarizes the front-end API functions that you can call to work with attributes.
Represents a backend operation in the server plug-in-in.
#include slapi-plugin.h
typedef struct backend Slapi_Backend;
Slapi_Backendis the data type for an opaque structure that represents a backend operation.The following table summarizes the front-end API functions that you can call to work with the backend operations.
slapi_backend_state_change_fnptr
slapi_backend_state_change_fnptrspecifies the prototype for a callback function, which allows a plug-in to register for callback, when a backend state changes.#include "slapi-plugin.h"
typedef void (*slapi_backend_state_change_fnptr)(void *handle,
char *be_name, int old_be_state, int new_be_state);The function has the following parameters:
Pointer or reference to the address of the specified function.
The slapi_register_backend_state_change() function enables a plug-in to register for callback when the state of a backend changes. You may need to keep track of backend state changes when writing custom plug-ins.
slapi_register_backend_state_change()
slapi_unregister_backend_state_change()
Represents a the component ID in a directory entry.
#include slapi-plugin.h
typedef struct slapi_componentid Slapi_ComponentId;
Slapi_ComponentIdis the data type for an opaque structure that represents a the component ID in a directory entry.
Represents a callback for evaluating computed attributes.
#include "slapi-plugin.h"
typedef int (*slapi_compute_callback_t)
(computed_attr_context *c, char* type,
Slapi_Entry *e, slapi_compute_output_t outputfn);The function has the following parameters:
- -1 if the function is not responsible for generating the computed attribute.
![]()
- 0 if the function successfully generates the computed attribute.
![]()
- An LDAP error code if an error occurred.
![]()
slapi_compute_callback_tspecifies the prototype for a callback function that is called by the server when generating a computed attribute. If you want to use computed attributes, you should write a function of this type.
Represents a prototype for an output function for contributed attributes.
#include "slapi-plugin.h"
typedef int (*slapi_compute_output_t)
(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e);The function has the following parameters:
- 0 if the function successfully BER-encodes the computed attribute and adds it to the BER element to be sent to the client.
![]()
- An LDAP error code if an error occurred.
![]()
slapi_compute_output_tspecifies the prototype for a callback function that BER-encodes a computed attribute and appends it to the BER element to be sent to the client.You do not need to define a function of this type. The server will pass a function of this type your
slapi_compute_callback_tfunction. In yourslapi_compute_callback_tfunction, you need to call thisslapi_compute_output_tfunction.my_compute_callback(computed_attr_context *c, char* type,
Slapi_Entry *e, slapi_compute_output_t outputfn)/* Call the output function after created the computed
attribute and setting its values. */
rc = (*outputfn) (c, &my_computed_attr, e);
In the example above, the
slapi_compute_output_tfunctionoutputfnis passed in as an argument tomy_compute_callbackfunction. After generating the computed attribute, you need to calloutputfn, passing it the context, the newly created attribute, and the entry.outputfnBER-encodes the attribute and appends it to the BER element to be sent to the client.Note that you do not need to define
outputfnyourself. You just need to call the function passed in as the last statement from the callback.
#include slapi-plugin.h
typedef struct conn Slapi_Connection;
Slapi_Connectionis the data type for an opaque structure that represents a connection.
Represents a condition variable in a directory entry.
#include slapi-plugin.h
typedef struct slapi_condvar Slapi_CondVar;
Slapi_CondVaris the data type for an opaque structure that represents a synchronization lock in the server plug-in.The following table summarizes the front-end API functions that you can call to modify synchronization locks in the server plug-in.
Represents a distinguished name in a directory entry.
#include slapi-plugin.h
typedef struct slapi_dn Slapi_DN;
Slapi_DNis the data type for an opaque structure that represents a distinguished name in the server plug-in.The following table summarizes the front-end API functions that you can call to work with distinguished names.
Represents an entry in the directory.
#include slapi-plugin.h
typedef struct slapi_entry Slapi_Entry;
Slapi_Entryis the data type for an opaque structure that represents an entry in the directory. In certain cases, your server plug-in may need to work with an entry in the directory.The following table summarizes the front-end API functions that you can call to work with entries.
Check if values present in an entry's RDN are also present as attribute values
Determine if an entry complies with the schema for its object class
#include slapi-plugin.h
typedef struct slapi_filter Slapi_Filter;
Slapi_Filteris the data type for an opaque structure that represents an search filter. (For more information on search filters, see "Working with Search Filters.")The following table summarizes the front-end API functions that you can call to work with filters.
#include slapi-plugin.h
typedef struct slapi_matchingRuleEntry Slapi_MatchingRuleEntry;
Slapi_MatchingRuleEntryis the data type for an opaque structure that represents a matching rule.The following table summarizes the front-end API functions that you can call to work with matching rules.
Represents a single LDAP modification to a directory entry.
#include slapi-plugin.h
typedef struct slapi_mod Slapi_Mod;
Slapi_Modis the data type for an opaque structure that represents LDAPMod modifications to an attribute in a directory entry.The following table summarizes the front-end API functions that you can call to manipulate directory entries.
LDAPMod and Slapi_Mods
Represents two or more LDAP modifications to a directory entry
#include slapi-plugin.h
typedef struct slapi_mods Slapi_Mods;
Slapi_Modsis the data type for an opaque structure that represents LDAPMod manipulations that can be made to a directory entry.The following table summarizes the front-end API functions that you can call to manipulate directory entries.