summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Megginson <rmeggins@redhat.com>2010-02-08 08:57:52 -0700
committerRich Megginson <rmeggins@redhat.com>2010-02-17 15:04:02 -0700
commit834c706f04e53bb3ca95caa31c6e1166ad79210e (patch)
treee002cfe1db898002465b4545c6b38be39b9d615e
parent3e5e21c68afc5ff38d0d843fafaddd145e4d38f5 (diff)
downloadds-834c706f04e53bb3ca95caa31c6e1166ad79210e.tar.gz
ds-834c706f04e53bb3ca95caa31c6e1166ad79210e.tar.xz
ds-834c706f04e53bb3ca95caa31c6e1166ad79210e.zip
Do not use syntax plugins directly for filters, indexing
There were many places in the server code that directly used the syntax plugin for the attribute. If the attribute schema definition specified a matching rule, we must use that matching rule for matching values of that attribute, filtering that attribute, and generating index keys for values of that attribute. New internal and plugin APIs have been added that use the Slapi_Attr* instead of using the syntax plugin directly. The new API will determine which matching rule to apply based on the schema definition.
-rw-r--r--ldap/servers/slapd/attr.c76
-rw-r--r--ldap/servers/slapd/attrsyntax.c10
-rw-r--r--ldap/servers/slapd/back-ldbm/back-ldbm.h4
-rw-r--r--ldap/servers/slapd/back-ldbm/filterindex.c76
-rw-r--r--ldap/servers/slapd/back-ldbm/index.c20
-rw-r--r--ldap/servers/slapd/back-ldbm/ldbm_attr.c19
-rw-r--r--ldap/servers/slapd/back-ldbm/ldif2ldbm.c2
-rw-r--r--ldap/servers/slapd/back-ldbm/proto-back-ldbm.h3
-rw-r--r--ldap/servers/slapd/back-ldbm/sort.c8
-rw-r--r--ldap/servers/slapd/back-ldbm/vlv.c22
-rw-r--r--ldap/servers/slapd/back-ldbm/vlv_srch.c4
-rw-r--r--ldap/servers/slapd/back-ldbm/vlv_srch.h3
-rw-r--r--ldap/servers/slapd/entry.c23
-rw-r--r--ldap/servers/slapd/filtercmp.c19
-rw-r--r--ldap/servers/slapd/pblock.c104
-rw-r--r--ldap/servers/slapd/plugin_mr.c23
-rw-r--r--ldap/servers/slapd/plugin_syntax.c331
-rw-r--r--ldap/servers/slapd/proto-slap.h26
-rw-r--r--ldap/servers/slapd/schema.c4
-rw-r--r--ldap/servers/slapd/slap.h27
-rw-r--r--ldap/servers/slapd/slapi-plugin-compat4.h6
-rw-r--r--ldap/servers/slapd/slapi-plugin.h29
-rw-r--r--ldap/servers/slapd/valueset.c31
23 files changed, 675 insertions, 195 deletions
diff --git a/ldap/servers/slapd/attr.c b/ldap/servers/slapd/attr.c
index 89aa9f51..97a9c923 100644
--- a/ldap/servers/slapd/attr.c
+++ b/ldap/servers/slapd/attr.c
@@ -290,11 +290,17 @@ slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_loc
{
a->a_plugin = asi->asi_plugin;
a->a_flags = asi->asi_flags;
+ a->a_mr_eq_plugin = asi->asi_mr_eq_plugin;
+ a->a_mr_ord_plugin = asi->asi_mr_ord_plugin;
+ a->a_mr_sub_plugin = asi->asi_mr_sub_plugin;
}
else
{
a->a_plugin = NULL; /* XXX - should be rare */
a->a_flags = 0; /* XXX - should be rare */
+ a->a_mr_eq_plugin = NULL;
+ a->a_mr_ord_plugin = NULL;
+ a->a_mr_sub_plugin = NULL;
}
attr_syntax_return_locking_optional( asi, use_lock );
@@ -779,7 +785,7 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
* input vals array for duplicates
*/
Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray(a->a_type, a->a_plugin, vals, &vtree, &duplicate_index);
+ rc= valuetree_add_valuearray(a, vals, &vtree, &duplicate_index);
valuetree_free(&vtree);
was_present_null = 1;
} else {
@@ -892,3 +898,71 @@ attr_check_minmax ( const char *attr_name, char *value, long minval, long maxval
return retVal;
}
+
+/**
+ Returns the function which can be used to compare (like memcmp/strcmp)
+ two values of this type of attribute. The comparison function will use
+ the ORDERING matching rule if available, or the default comparison
+ function from the syntax plugin.
+ Note: if there is no ORDERING matching rule, and the syntax does not
+ provide an ordered compare function, this function will return
+ LDAP_PROTOCOL_ERROR and compare_fn will be NULL.
+ Returns LDAP_SUCCESS if successful and sets *compare_fn to the function.
+ */
+int
+attr_get_value_cmp_fn(const Slapi_Attr *attr, value_compare_fn_type *compare_fn)
+{
+ int rc = LDAP_PROTOCOL_ERROR;
+
+ LDAPDebug0Args(LDAP_DEBUG_TRACE,
+ "=> slapi_attr_get_value_cmp_fn\n");
+
+ *compare_fn = NULL;
+
+ if (attr == NULL) {
+ LDAPDebug0Args(LDAP_DEBUG_TRACE,
+ "<= slapi_attr_get_value_cmp_fn no attribute given\n");
+ rc = LDAP_PARAM_ERROR; /* unkonwn */
+ goto done;
+ }
+
+ if (attr->a_mr_ord_plugin && attr->a_mr_ord_plugin->plg_mr_compare) {
+ *compare_fn = (value_compare_fn_type) attr->a_mr_ord_plugin->plg_mr_compare;
+ rc = LDAP_SUCCESS;
+ goto done;
+ }
+
+ if ((attr->a_plugin->plg_syntax_flags & SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0) {
+ LDAPDebug2Args(LDAP_DEBUG_TRACE,
+ "<= slapi_attr_get_value_cmp_fn syntax [%s] for attribute [%s] does not support ordering\n",
+ attr->a_plugin->plg_syntax_oid, attr->a_type);
+ goto done;
+ }
+
+ if (attr->a_plugin->plg_syntax_filter_ava == NULL) {
+ LDAPDebug2Args(LDAP_DEBUG_TRACE,
+ "<= slapi_attr_get_value_cmp_fn syntax [%s] for attribute [%s] does not support equality matching\n",
+ attr->a_plugin->plg_syntax_oid, attr->a_type);
+ goto done;
+ }
+
+ if (attr->a_plugin->plg_syntax_compare == NULL) {
+ LDAPDebug2Args(LDAP_DEBUG_TRACE,
+ "<= slapi_attr_get_value_cmp_fn syntax [%s] for attribute [%s] does not have a compare function\n",
+ attr->a_plugin->plg_syntax_oid, attr->a_type);
+ goto done;
+ }
+
+ *compare_fn = (value_compare_fn_type)attr->a_plugin->plg_syntax_compare;
+ rc = LDAP_SUCCESS;
+
+done:
+ LDAPDebug0Args(LDAP_DEBUG_TRACE, "<= slapi_attr_get_value_cmp_fn \n");
+ return rc;
+}
+
+const char *
+attr_get_syntax_oid(const Slapi_Attr *attr)
+{
+ return attr->a_plugin->plg_syntax_oid;
+}
diff --git a/ldap/servers/slapd/attrsyntax.c b/ldap/servers/slapd/attrsyntax.c
index e88f4ba1..11b272a0 100644
--- a/ldap/servers/slapd/attrsyntax.c
+++ b/ldap/servers/slapd/attrsyntax.c
@@ -674,6 +674,9 @@ attr_syntax_create(
a.asi_origin = (char **)attr_origins;
a.asi_plugin = plugin_syntax_find( attr_syntax );
a.asi_syntaxlength = syntaxlength;
+ a.asi_mr_eq_plugin = plugin_mr_find( mr_equality );
+ a.asi_mr_ord_plugin = plugin_mr_find( mr_ordering );
+ a.asi_mr_sub_plugin = plugin_mr_find( mr_substring );
a.asi_flags = flags;
/*
@@ -760,10 +763,9 @@ slapi_attr_get_oid_copy( const Slapi_Attr *a, char **oidp )
int
slapi_attr_get_syntax_oid_copy( const Slapi_Attr *a, char **oidp )
{
- void *pi = NULL;
-
- if (a && (slapi_attr_type2plugin(a->a_type, &pi) == 0)) {
- *oidp = slapi_ch_strdup(plugin_syntax2oid(pi));
+ const char *oid;
+ if (a && ((oid = attr_get_syntax_oid(a)))) {
+ *oidp = slapi_ch_strdup(oid);
return( 0 );
} else {
*oidp = NULL;
diff --git a/ldap/servers/slapd/back-ldbm/back-ldbm.h b/ldap/servers/slapd/back-ldbm/back-ldbm.h
index 06cabf2c..1153ff37 100644
--- a/ldap/servers/slapd/back-ldbm/back-ldbm.h
+++ b/ldap/servers/slapd/back-ldbm/back-ldbm.h
@@ -467,7 +467,6 @@ struct attrinfo {
* yet. */
#define IS_INDEXED( a ) ( a & INDEX_ANY )
- void *ai_plugin; /* the syntax plugin for this attribute */
char **ai_index_rules; /* matching rule OIDs */
void *ai_dblayer; /* private data used by the dblayer code */
PRInt32 ai_dblayer_count; /* used by the dblayer code */
@@ -475,7 +474,7 @@ struct attrinfo {
attrcrypt_private *ai_attrcrypt; /* private data used by the attribute encryption code (eg is it enabled or not) */
value_compare_fn_type ai_key_cmp_fn; /* function used to compare two index keys -
The function is the compare function provided by
- ai_plugin - this function is used to order
+ attr_get_value_cmp_fn - this function is used to order
the keys in the index so that we can use ORDERING
searches. In order for this function to be used,
the syntax plugin must define a compare function,
@@ -495,6 +494,7 @@ struct attrinfo {
* len value(s) are stored here. If not specified,
* the default length triplet is 2, 3, 2.
*/
+ Slapi_Attr ai_sattr; /* interface to syntax and matching rule plugins */
};
#define MAXDBCACHE 20
diff --git a/ldap/servers/slapd/back-ldbm/filterindex.c b/ldap/servers/slapd/back-ldbm/filterindex.c
index d41829f8..b77103b6 100644
--- a/ldap/servers/slapd/back-ldbm/filterindex.c
+++ b/ldap/servers/slapd/back-ldbm/filterindex.c
@@ -61,7 +61,8 @@ static IDList * range_candidates(
char *type,
struct berval *low_val,
struct berval *high_val,
- int *err
+ int *err,
+ const Slapi_Attr *sattr
);
static IDList *
keys2idl(
@@ -194,8 +195,8 @@ ava_candidates(
struct berval *bval;
Slapi_Value **ivals;
IDList *idl;
- void *pi;
int unindexed = 0;
+ Slapi_Attr sattr;
LDAPDebug( LDAP_DEBUG_TRACE, "=> ava_candidates\n", 0, 0, 0 );
@@ -205,6 +206,8 @@ ava_candidates(
return( NULL );
}
+ slapi_attr_init(&sattr, type);
+
#ifdef LDAP_DEBUG
if ( LDAPDebugLevelIsSet( LDAP_DEBUG_TRACE )) {
char *op = NULL;
@@ -231,15 +234,17 @@ ava_candidates(
switch ( ftype ) {
case LDAP_FILTER_GE:
- idl = range_candidates(pb, be, type, bval, NULL, err);
+ idl = range_candidates(pb, be, type, bval, NULL, err, &sattr);
LDAPDebug( LDAP_DEBUG_TRACE, "<= ava_candidates %lu\n",
(u_long)IDL_NIDS(idl), 0, 0 );
- return( idl );
+ goto done;
+ break;
case LDAP_FILTER_LE:
- idl = range_candidates(pb, be, type, NULL, bval, err);
+ idl = range_candidates(pb, be, type, NULL, bval, err, &sattr);
LDAPDebug( LDAP_DEBUG_TRACE, "<= ava_candidates %lu\n",
(u_long)IDL_NIDS(idl), 0, 0 );
- return( idl );
+ goto done;
+ break;
case LDAP_FILTER_EQUALITY:
indextype = (char*)indextype_EQUALITY;
break;
@@ -248,15 +253,6 @@ ava_candidates(
break;
}
- /*
- * get the keys corresponding to this assertion value
- */
- if ( slapi_attr_type2plugin( type, &pi ) != 0 ) {
- LDAPDebug( LDAP_DEBUG_TRACE, " slapi_filter_get_ava no plugin\n",
- 0, 0, 0 );
- return( NULL );
- }
-
/* This code is result of performance anlysis; we are trying to
* optimize our equality filter processing -- mainly by limiting
* malloc/free calls.
@@ -282,7 +278,7 @@ ava_candidates(
ptr[1]=NULL;
ivals=ptr;
- slapi_call_syntax_assertion2keys_ava_sv( pi, &tmp, (Slapi_Value ***)&ivals, LDAP_FILTER_EQUALITY_FAST);
+ slapi_attr_assertion2keys_ava_sv( &sattr, &tmp, (Slapi_Value ***)&ivals, LDAP_FILTER_EQUALITY_FAST);
idl = keys2idl( be, type, indextype, ivals, err, &unindexed );
if ( unindexed ) {
unsigned int opnote = SLAPI_OP_NOTE_UNINDEXED;
@@ -306,12 +302,13 @@ ava_candidates(
} else {
slapi_value_init_berval(&sv, bval);
ivals=NULL;
- slapi_call_syntax_assertion2keys_ava_sv( pi, &sv, &ivals, ftype );
+ slapi_attr_assertion2keys_ava_sv( &sattr, &sv, &ivals, ftype );
value_done(&sv);
if ( ivals == NULL || *ivals == NULL ) {
LDAPDebug( LDAP_DEBUG_TRACE,
"<= ava_candidates ALLIDS (no keys)\n", 0, 0, 0 );
- return( idl_allids( be ) );
+ idl = idl_allids( be );
+ goto done;
}
idl = keys2idl( be, type, indextype, ivals, err, &unindexed );
if ( unindexed ) {
@@ -322,6 +319,8 @@ ava_candidates(
LDAPDebug( LDAP_DEBUG_TRACE, "<= ava_candidates %lu\n",
(u_long)IDL_NIDS(idl), 0, 0 );
}
+done:
+ attr_done(&sattr);
return( idl );
}
@@ -520,28 +519,18 @@ range_candidates(
char *type,
struct berval *low_val,
struct berval *high_val,
- int *err
+ int *err,
+ const Slapi_Attr *sattr
)
{
IDList *idl;
struct berval *low = NULL, *high = NULL;
struct berval **lows = NULL, **highs = NULL;
- void *pi;
LDAPDebug(LDAP_DEBUG_TRACE, "=> range_candidates attr=%s\n", type, 0, 0);
- /*
- * get the keys corresponding to the assertion values
- */
-
- if ( slapi_attr_type2plugin( type, &pi ) != 0 ) {
- LDAPDebug( LDAP_DEBUG_TRACE, " slapi_filter_get_ava no plugin\n",
- 0, 0, 0 );
- return( NULL );
- }
-
if (low_val != NULL) {
- slapi_call_syntax_assertion2keys_ava(pi, low_val, &lows, LDAP_FILTER_EQUALITY);
+ slapi_attr_assertion2keys_ava(sattr, low_val, &lows, LDAP_FILTER_EQUALITY);
if (lows == NULL || *lows == NULL) {
LDAPDebug( LDAP_DEBUG_TRACE,
"<= range_candidates ALLIDS (no keys)\n", 0, 0, 0 );
@@ -551,7 +540,7 @@ range_candidates(
}
if (high_val != NULL) {
- slapi_call_syntax_assertion2keys_ava(pi, high_val, &highs, LDAP_FILTER_EQUALITY);
+ slapi_attr_assertion2keys_ava(sattr, high_val, &highs, LDAP_FILTER_EQUALITY);
if (highs == NULL || *highs == NULL) {
LDAPDebug( LDAP_DEBUG_TRACE,
"<= range_candidates ALLIDS (no keys)\n", 0, 0, 0 );
@@ -698,7 +687,11 @@ list_candidates(
is_bounded_range = 0;
}
if (is_bounded_range) {
- idl = range_candidates(pb, be, tpairs[0], vpairs[0], vpairs[1], err);
+ Slapi_Attr sattr;
+
+ slapi_attr_init(&sattr, tpairs[0]);
+ idl = range_candidates(pb, be, tpairs[0], vpairs[0], vpairs[1], err, &sattr);
+ attr_done(&sattr);
LDAPDebug( LDAP_DEBUG_TRACE, "<= list_candidates %lu\n",
(u_long)IDL_NIDS(idl), 0, 0 );
goto out;
@@ -734,8 +727,12 @@ list_candidates(
}
else if (fpairs[1] == f)
{
+ Slapi_Attr sattr;
+
+ slapi_attr_init(&sattr, tpairs[0]);
tmp = range_candidates(pb, be, tpairs[0],
- vpairs[0], vpairs[1], err);
+ vpairs[0], vpairs[1], err, &sattr);
+ attr_done(&sattr);
if (tmp == NULL && ftype == LDAP_FILTER_AND)
{
LDAPDebug( LDAP_DEBUG_TRACE,
@@ -839,10 +836,10 @@ substring_candidates(
char *type, *initial, *final;
char **any;
IDList *idl;
- void *pi;
Slapi_Value **ivals;
int unindexed = 0;
unsigned int opnote = SLAPI_OP_NOTE_UNINDEXED;
+ Slapi_Attr sattr;
LDAPDebug( LDAP_DEBUG_TRACE, "=> sub_candidates\n", 0, 0, 0 );
@@ -856,12 +853,9 @@ substring_candidates(
* get the index keys corresponding to the substring
* assertion values
*/
- if ( slapi_attr_type2plugin( type, &pi ) != 0 ) {
- LDAPDebug( LDAP_DEBUG_TRACE, " sub_candidates no plugin\n",
- 0, 0, 0 );
- return( NULL );
- }
- slapi_call_syntax_assertion2keys_sub_sv( pi, initial, any, final, &ivals );
+ slapi_attr_init(&sattr, type);
+ slapi_attr_assertion2keys_sub_sv( &sattr, initial, any, final, &ivals );
+ attr_done(&sattr);
if ( ivals == NULL || *ivals == NULL ) {
slapi_pblock_set( pb, SLAPI_OPERATION_NOTES, &opnote );
LDAPDebug( LDAP_DEBUG_TRACE,
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
index d7afb471..f26e3d37 100644
--- a/ldap/servers/slapd/back-ldbm/index.c
+++ b/ldap/servers/slapd/back-ldbm/index.c
@@ -54,7 +54,7 @@ static const char *errmsg = "database index operation failed";
static int is_indexed (const char* indextype, int indexmask, char** index_rules);
static Slapi_Value **
valuearray_minus_valuearray(
- void *plugin,
+ const Slapi_Attr *sattr,
Slapi_Value **a,
Slapi_Value **b
);
@@ -1848,8 +1848,7 @@ index_addordel_values_ext_sv(
/* on delete, only remove the equality index if the
* BE_INDEX_EQUALITY flag is set.
*/
- slapi_call_syntax_values2keys_sv( ai->ai_plugin, vals, &ivals,
- LDAP_FILTER_EQUALITY );
+ slapi_attr_values2keys_sv( &ai->ai_sattr, vals, &ivals, LDAP_FILTER_EQUALITY );
err = addordel_values_sv( be, db, basetype, indextype_EQUALITY,
ivals != NULL ? ivals : vals, id, flags, txn, ai, idl_disposition, NULL );
@@ -1866,8 +1865,7 @@ index_addordel_values_ext_sv(
* approximate index entry
*/
if ( ai->ai_indexmask & INDEX_APPROX ) {
- slapi_call_syntax_values2keys_sv( ai->ai_plugin, vals, &ivals,
- LDAP_FILTER_APPROX );
+ slapi_attr_values2keys_sv( &ai->ai_sattr, vals, &ivals, LDAP_FILTER_APPROX );
if ( ivals != NULL ) {
err = addordel_values_sv( be, db, basetype,
@@ -1892,19 +1890,19 @@ index_addordel_values_ext_sv(
/* prepare pblock to pass ai_substr_lens */
pblock_init( &pipb );
slapi_pblock_set( &pipb, SLAPI_SYNTAX_SUBSTRLENS, ai->ai_substr_lens );
- slapi_call_syntax_values2keys_sv_pb( ai->ai_plugin, vals, &ivals,
+ slapi_attr_values2keys_sv_pb( &ai->ai_sattr, vals, &ivals,
LDAP_FILTER_SUBSTRINGS, &pipb );
origvals = ivals;
/* delete only: if the attribute has multiple values,
* figure out the substrings that should remain
- * by slapi_call_syntax_values2keys,
+ * by slapi_attr_values2keys,
* then get rid of them from the being deleted values
*/
if ( evals != NULL ) {
- slapi_call_syntax_values2keys_sv_pb( ai->ai_plugin, evals,
+ slapi_attr_values2keys_sv_pb( &ai->ai_sattr, evals,
&esubvals, LDAP_FILTER_SUBSTRINGS, &pipb );
- substresult = valuearray_minus_valuearray( ai->ai_plugin, ivals, esubvals );
+ substresult = valuearray_minus_valuearray( &ai->ai_sattr, ivals, esubvals );
ivals = substresult;
valuearray_free( &esubvals );
}
@@ -2070,7 +2068,7 @@ bvals_strcasecmp(const struct berval *a, const struct berval *b)
/* the returned array of Slapi_Value needs to be freed. */
static Slapi_Value **
valuearray_minus_valuearray(
- void *plugin,
+ const Slapi_Attr *sattr,
Slapi_Value **a,
Slapi_Value **b
)
@@ -2081,7 +2079,7 @@ valuearray_minus_valuearray(
value_compare_fn_type cmp_fn;
/* get berval comparison function */
- plugin_call_syntax_get_compare_fn(plugin, &cmp_fn);
+ attr_get_value_cmp_fn(sattr, &cmp_fn);
if (cmp_fn == NULL) {
cmp_fn = (value_compare_fn_type)bvals_strcasecmp;
}
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attr.c b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
index 1042cf7e..3866e121 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_attr.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
@@ -61,6 +61,7 @@ attrinfo_delete(struct attrinfo **pp)
slapi_ch_free((void**)&((*pp)->ai_type));
slapi_ch_free((void**)(*pp)->ai_index_rules);
slapi_ch_free((void**)&((*pp)->ai_attrcrypt));
+ attr_done(&((*pp)->ai_sattr));
slapi_ch_free((void**)pp);
*pp= NULL;
}
@@ -194,11 +195,15 @@ attr_index_config(
}
for ( i = 0; attrs[i] != NULL; i++ ) {
int need_compare_fn = 0;
- char *attrsyntax_oid = NULL;
+ const char *attrsyntax_oid = NULL;
a = attrinfo_new();
+ slapi_attr_init(&a->ai_sattr, attrs[i]);
+ /* we can't just set a->ai_type to the type from a->ai_sattr
+ if the type has attroptions or subtypes, ai_sattr.a_type will
+ contain them - but for the purposes of indexing, we don't want
+ them */
a->ai_type = slapi_attr_basetype( attrs[i], NULL, 0 );
- slapi_attr_type2plugin( a->ai_type, &a->ai_plugin );
- attrsyntax_oid = slapi_ch_strdup(plugin_syntax2oid(a->ai_plugin));
+ attrsyntax_oid = attr_get_syntax_oid(&a->ai_sattr);
if ( argc == 1 ) {
a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
INDEX_APPROX | INDEX_SUB);
@@ -301,7 +306,6 @@ attr_index_config(
}
}
- slapi_ch_free_string(&attrsyntax_oid);
/* initialize the IDL code's private data */
return_value = idl_init_private(be, a);
if (0 != return_value) {
@@ -322,11 +326,11 @@ attr_index_config(
}
if (need_compare_fn) {
- int rc = plugin_call_syntax_get_compare_fn( a->ai_plugin, &a->ai_key_cmp_fn );
+ int rc = attr_get_value_cmp_fn( &a->ai_sattr, &a->ai_key_cmp_fn );
if (rc != LDAP_SUCCESS) {
LDAPDebug(LDAP_DEBUG_ANY,
- "The attribute [%s] does not have a valid ORDERING matching rule\n",
- a->ai_type, 0, 0);
+ "The attribute [%s] does not have a valid ORDERING matching rule - error %d:s\n",
+ a->ai_type, rc, ldap_err2string(rc));
a->ai_key_cmp_fn = NULL;
}
}
@@ -358,6 +362,7 @@ attr_create_empty(backend *be,char *type,struct attrinfo **ai)
{
ldbm_instance *inst = (ldbm_instance *) be->be_instance_info;
struct attrinfo *a = attrinfo_new();
+ slapi_attr_init(&a->ai_sattr, type);
a->ai_type = slapi_ch_strdup(type);
if ( avl_insert( &inst->inst_attrs, a, ainfo_cmp, ainfo_dup ) != 0 ) {
/* duplicate - existing version updated */
diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
index 70a2b1fe..ce79c6fe 100644
--- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
+++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
@@ -1408,7 +1408,7 @@ ldbm_back_ldbm2ldif( Slapi_PBlock *pb )
&psrdn, NULL, 0,
run_from_cmdline, NULL);
if (rc) {
- LDAPDebugArg(LDAP_DEBUG_ANY,
+ LDAPDebug1Arg(LDAP_DEBUG_ANY,
"ldbm2ldif: Failed to get dn of ID "
"%d\n", pid);
slapi_ch_free_string(&rdn);
diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
index a64919c8..f12d41d5 100644
--- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
+++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
@@ -418,12 +418,13 @@ int ldbm_back_rmdb( Slapi_PBlock *pb );
*/
struct sort_spec_thing
{
- char *type;
+ char *type; /* attribute type */
char *matchrule; /* Matching rule string */
int order; /* 0 == ascending, 1 == decending */
struct sort_spec_thing *next; /* Link to the next one */
Slapi_PBlock *mr_pb; /* For matchrule indexing */
value_compare_fn_type compare_fn; /* For non-matchrule indexing */
+ Slapi_Attr sattr;
};
typedef struct sort_spec_thing sort_spec_thing;
typedef struct sort_spec_thing sort_spec;
diff --git a/ldap/servers/slapd/back-ldbm/sort.c b/ldap/servers/slapd/back-ldbm/sort.c
index b7114f50..10d44170 100644
--- a/ldap/servers/slapd/back-ldbm/sort.c
+++ b/ldap/servers/slapd/back-ldbm/sort.c
@@ -71,6 +71,7 @@ static void sort_spec_thing_free(sort_spec_thing *s)
destroy_matchrule_indexer(s->mr_pb);
slapi_pblock_destroy (s->mr_pb);
}
+ attr_done(&s->sattr);
slapi_ch_free( (void**)&s);
}
@@ -100,6 +101,7 @@ static sort_spec_thing * sort_spec_thing_new(char *type, char* matchrule, int re
s->type = type;
s->matchrule = matchrule;
s->order = reverse;
+ slapi_attr_init(&s->sattr, type);
return s;
}
@@ -188,12 +190,8 @@ int sort_candidates(backend *be,int lookthrough_limit,time_t time_up, Slapi_PBlo
/* Iterate over the sort types */
for (this_s = s; this_s; this_s=this_s->next) {
if (NULL == this_s->matchrule) {
- void *pi;
int return_value = 0;
- return_value = slapi_attr_type2plugin( this_s->type, &pi );
- if (0 == return_value) {
- return_value = plugin_call_syntax_get_compare_fn( pi, &(this_s->compare_fn) );
- }
+ return_value = attr_get_value_cmp_fn( &this_s->sattr, &(this_s->compare_fn) );
if (return_value != 0 ) {
LDAPDebug( LDAP_DEBUG_TRACE, "Attempting to sort a non-ordered attribute (%s)\n",this_s->type, 0, 0 );
/* DBDB we should set the error type here */
diff --git a/ldap/servers/slapd/back-ldbm/vlv.c b/ldap/servers/slapd/back-ldbm/vlv.c
index db809c45..2402017d 100644
--- a/ldap/servers/slapd/back-ldbm/vlv.c
+++ b/ldap/servers/slapd/back-ldbm/vlv.c
@@ -564,9 +564,9 @@ vlv_create_key(struct vlvIndex* p, struct backentry* e)
int totalattrs;
if (p->vlv_sortkey[sortattr]->sk_matchruleoid==NULL)
{
- /* No matching rule. Syntax Plugin mangles value. */
+ /* No matching rule. mangle values according to matching rule or syntax */
Slapi_Value **va= valueset_get_valuearray(&attr->a_present_values);
- slapi_call_syntax_values2keys_sv( p->vlv_syntax_plugin[sortattr], va, &cvalue, LDAP_FILTER_EQUALITY );
+ slapi_attr_values2keys_sv( attr, va, &cvalue, LDAP_FILTER_EQUALITY );
valuearray_get_bervalarray(cvalue,&value);
/* XXXSD need to free some more stuff */
@@ -933,7 +933,10 @@ vlv_build_candidate_list_byvalue( struct vlvIndex* p, DBC *dbc, PRUint32 length,
invalue[1]= NULL;
if (p->vlv_sortkey[0]->sk_matchruleoid==NULL)
{
- slapi_call_syntax_values2keys(p->vlv_syntax_plugin[0],invalue,&typedown_value,LDAP_FILTER_EQUALITY); /* JCM SLOW FUNCTION */
+ Slapi_Attr sattr;
+ slapi_attr_init(&sattr, p->vlv_sortkey[0]->sk_attrtype);
+ slapi_attr_values2keys(&sattr,invalue,&typedown_value,LDAP_FILTER_EQUALITY); /* JCM SLOW FUNCTION */
+ attr_done(&sattr);
}
else
{
@@ -1484,14 +1487,19 @@ vlv_trim_candidates_byvalue(backend *be, const IDList *candidates, const sort_sp
*/
if (sort_control->matchrule==NULL)
{
- void *pi= NULL;
- if(slapi_attr_type2plugin(sort_control->type, &pi)==0)
+ attr_get_value_cmp_fn(&sort_control->sattr, &compare_fn);
+ if (compare_fn == NULL) {
+ LDAPDebug1Arg(LDAP_DEBUG_ANY, "vlv_trim_candidates_byvalue: "
+ "attempt to compare an unordered attribute [%s]\n",
+ sort_control->type);
+ compare_fn = slapi_berval_cmp;
+ }
+
{
struct berval *invalue[2];
invalue[0]= (struct berval *)&vlv_request_control->value; /* jcm: cast away const */
invalue[1]= NULL;
- slapi_call_syntax_values2keys(pi,invalue,&typedown_value,LDAP_FILTER_EQUALITY); /* JCM SLOW FUNCTION */
- plugin_call_syntax_get_compare_fn( pi, &compare_fn );
+ slapi_attr_values2keys(&sort_control->sattr,invalue,&typedown_value,LDAP_FILTER_EQUALITY); /* JCM SLOW FUNCTION */
if (compare_fn == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "vlv_trim_candidates_byvalue: "
"attempt to compare an unordered attribute",
diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.c b/ldap/servers/slapd/back-ldbm/vlv_srch.c
index d9a14a42..da59ba3d 100644
--- a/ldap/servers/slapd/back-ldbm/vlv_srch.c
+++ b/ldap/servers/slapd/back-ldbm/vlv_srch.c
@@ -534,7 +534,6 @@ vlvIndex_new()
p->vlv_sortkey= NULL;
p->vlv_filename= NULL;
p->vlv_mrpb= NULL;
- p->vlv_syntax_plugin= NULL;
p->vlv_indexlength_lock= PR_NewLock();
p->vlv_indexlength_cached= 0;
p->vlv_indexlength= 0;
@@ -572,7 +571,6 @@ vlvIndex_delete(struct vlvIndex** ppvs)
slapi_ch_free((void**)&((*ppvs)->vlv_name));
slapi_ch_free((void**)&((*ppvs)->vlv_filename));
slapi_ch_free((void**)&((*ppvs)->vlv_mrpb));
- slapi_ch_free((void**)&((*ppvs)->vlv_syntax_plugin));
PR_DestroyLock((*ppvs)->vlv_indexlength_lock);
slapi_ch_free((void**)ppvs);
*ppvs= NULL;
@@ -611,10 +609,8 @@ vlvIndex_init(struct vlvIndex* p, backend *be, struct vlvSearch* pSearch, const
int n;
for(n=0;p->vlv_sortkey[n]!=NULL;n++);
p->vlv_mrpb= (Slapi_PBlock**)slapi_ch_calloc(n+1,sizeof(Slapi_PBlock*));
- p->vlv_syntax_plugin= (void **)(Slapi_PBlock**)slapi_ch_calloc(n+1,sizeof(Slapi_PBlock*));
for(n=0;p->vlv_sortkey[n]!=NULL;n++)
{
- slapi_attr_type2plugin( p->vlv_sortkey[n]->sk_attrtype, &p->vlv_syntax_plugin[n] );
if(p->vlv_sortkey[n]->sk_matchruleoid!=NULL)
{
create_matchrule_indexer(&p->vlv_mrpb[n],p->vlv_sortkey[n]->sk_matchruleoid,p->vlv_sortkey[n]->sk_attrtype);
diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.h b/ldap/servers/slapd/back-ldbm/vlv_srch.h
index e32cf88b..331dbf7d 100644
--- a/ldap/servers/slapd/back-ldbm/vlv_srch.h
+++ b/ldap/servers/slapd/back-ldbm/vlv_srch.h
@@ -106,9 +106,6 @@ struct vlvIndex
/* Attribute Structure maps filename onto index */
struct attrinfo *vlv_attrinfo;
- /* Syntax Plugin. One for each LDAPsortkey */
- void **vlv_syntax_plugin;
-
/* Matching Rule PBlock. One for each LDAPsortkey */
Slapi_PBlock **vlv_mrpb;
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index 75b14979..00558f72 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -465,10 +465,10 @@ typedef struct _str2entry_attr {
struct valuearrayfast sa_present_values;
struct valuearrayfast sa_deleted_values;
int sa_numdups;
- struct slapdplugin *sa_pi;
value_compare_fn_type sa_comparefn;
Avlnode *sa_vtree;
CSN *sa_attributedeletioncsn;
+ Slapi_Attr sa_attr;
} str2entry_attr;
static void
@@ -479,10 +479,10 @@ entry_attr_init(str2entry_attr *sa, const char *type, int state)
valuearrayfast_init(&sa->sa_present_values,NULL);
valuearrayfast_init(&sa->sa_deleted_values,NULL);
sa->sa_numdups= 0;
- sa->sa_pi= NULL;
sa->sa_comparefn = NULL;
sa->sa_vtree= NULL;
sa->sa_attributedeletioncsn= NULL;
+ slapi_attr_init(&sa->sa_attr, type);
}
/*
@@ -829,18 +829,8 @@ str2entry_dupcheck( const char *dn, char *s, int flags, int read_stateinfo )
if ( check_for_duplicate_values )
{
- if ( slapi_attr_type2plugin( type,(void **)&(attrs[nattrs].sa_pi) ) != 0 )
- {
- LDAPDebug( LDAP_DEBUG_ANY,
- "<= str2entry_dupcheck NULL (slapi_attr_type2plugin)\n",
- 0, 0, 0 );
- slapi_entry_free( e ); e = NULL;
- if (retmalloc) slapi_ch_free_string(&valuecharptr);
- if (freetype) slapi_ch_free_string(&type);
- goto free_and_return;
- }
/* Get the comparison function for later use */
- plugin_call_syntax_get_compare_fn( attrs[nattrs].sa_pi, &(attrs[nattrs].sa_comparefn));
+ attr_get_value_cmp_fn( &attrs[nattrs].sa_attr, &(attrs[nattrs].sa_comparefn));
/*
* If the compare function wasn't available,
* we have to revert to AVL-tree-based dup checking,
@@ -904,9 +894,9 @@ str2entry_dupcheck( const char *dn, char *s, int flags, int read_stateinfo )
if (sa->sa_present_values.num > STR2ENTRY_VALUE_DUPCHECK_THRESHOLD)
{
/* Make the tree from the existing attr values */
- rc= valuetree_add_valuearray( sa->sa_type, sa->sa_pi, sa->sa_present_values.va, &sa->sa_vtree, NULL);
+ rc= valuetree_add_valuearray( &sa->sa_attr, sa->sa_present_values.va, &sa->sa_vtree, NULL);
/* Check if the value already exists, in the tree. */
- rc= valuetree_add_value( sa->sa_type, sa->sa_pi, value, &sa->sa_vtree);
+ rc= valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
fast_dup_check = 0;
}
else
@@ -927,7 +917,7 @@ str2entry_dupcheck( const char *dn, char *s, int flags, int read_stateinfo )
else
{
/* Check if the value already exists, in the tree. */
- rc = valuetree_add_value( sa->sa_type, sa->sa_pi, value, &sa->sa_vtree);
+ rc = valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
}
}
@@ -1078,6 +1068,7 @@ free_and_return:
valuearrayfast_done(&attrs[ i ].sa_present_values);
valuearrayfast_done(&attrs[ i ].sa_deleted_values);
valuetree_free( &attrs[ i ].sa_vtree );
+ attr_done( &attrs[ i ].sa_attr );
}
if (tree_attr_checking)
{
diff --git a/ldap/servers/slapd/filtercmp.c b/ldap/servers/slapd/filtercmp.c
index 05916815..20a42a29 100644
--- a/ldap/servers/slapd/filtercmp.c
+++ b/ldap/servers/slapd/filtercmp.c
@@ -85,17 +85,15 @@ static PRUint32 stir(PRUint32 hash, PRUint32 x)
}
#define STIR(h) (h) = stir((h), 0x2EC6DEAD);
-static Slapi_Value **get_normalized_value(struct ava *ava)
+static Slapi_Value **get_normalized_value(const Slapi_Attr *sattr, struct ava *ava)
{
- void *plugin;
Slapi_Value *svlist[2], **keylist, sv;
- slapi_attr_type2plugin(ava->ava_type, &plugin);
sv.bv = ava->ava_value;
sv.v_csnset = NULL;
svlist[0] = &sv;
svlist[1] = NULL;
- if ((slapi_call_syntax_values2keys_sv(plugin, svlist, &keylist,
+ if ((slapi_attr_values2keys_sv(sattr, svlist, &keylist,
LDAP_FILTER_EQUALITY) != 0) ||
!keylist || !keylist[0])
return NULL;
@@ -168,6 +166,7 @@ void filter_compute_hash(struct slapi_filter *f)
Slapi_Value **keylist;
Slapi_PBlock *pb;
struct berval *inval[2], **outval;
+ Slapi_Attr sattr;
if (! hash_filters)
return;
@@ -178,7 +177,9 @@ void filter_compute_hash(struct slapi_filter *f)
case LDAP_FILTER_GE:
case LDAP_FILTER_LE:
case LDAP_FILTER_APPROX:
- keylist = get_normalized_value(&f->f_ava);
+ slapi_attr_init(&sattr, f->f_ava.ava_type);
+ keylist = get_normalized_value(&sattr, &f->f_ava);
+ attr_done(&sattr);
if (keylist) {
h = addhash_str(h, f->f_avtype);
STIR(h);
@@ -349,6 +350,7 @@ int slapi_filter_compare(struct slapi_filter *f1, struct slapi_filter *f2)
Slapi_PBlock *pb1, *pb2;
struct berval *inval1[2], *inval2[2], **outval1, **outval2;
int ret;
+ Slapi_Attr sattr;
LDAPDebug(LDAP_DEBUG_TRACE, "=> filter compare\n", 0, 0, 0);
@@ -376,19 +378,22 @@ int slapi_filter_compare(struct slapi_filter *f1, struct slapi_filter *f2)
ret = 1;
break;
}
- key1 = get_normalized_value(&f1->f_ava);
+ slapi_attr_init(&sattr, f1->f_ava.ava_type);
+ key1 = get_normalized_value(&sattr, &f1->f_ava);
if (key1) {
- key2 = get_normalized_value(&f2->f_ava);
+ key2 = get_normalized_value(&sattr, &f2->f_ava);
if (key2) {
ret = memcmp(slapi_value_get_string(key1[0]),
slapi_value_get_string(key2[0]),
slapi_value_get_length(key1[0]));
valuearray_free(&key1);
valuearray_free(&key2);
+ attr_done(&sattr);
break;
}
valuearray_free(&key1);
}
+ attr_done(&sattr);
ret = 1;
break;
case LDAP_FILTER_PRESENT:
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
index 20ead29a..b5d994ad 100644
--- a/ldap/servers/slapd/pblock.c
+++ b/ldap/servers/slapd/pblock.c
@@ -1094,7 +1094,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
}
(*(IFP *)value) = pblock->pb_plugin->plg_syntax_compare;
break;
- case SLAPI_SYNTAX_SUBSTRLENS:
+ case SLAPI_SYNTAX_SUBSTRLENS: /* aka SLAPI_MR_SUBSTRLENS */
(*(int **)value) = pblock->pb_substrlens;
break;
case SLAPI_PLUGIN_SYNTAX_VALIDATE:
@@ -1376,6 +1376,56 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
(*(unsigned int *) value) = pblock->pb_mr_usage;
break;
+ /* new style matching rule syntax plugin functions */
+ case SLAPI_PLUGIN_MR_FILTER_AVA:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_filter_ava;
+ break;
+ case SLAPI_PLUGIN_MR_FILTER_SUB:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_filter_sub;
+ break;
+ case SLAPI_PLUGIN_MR_VALUES2KEYS:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_values2keys;
+ break;
+ case SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_assertion2keys_ava;
+ break;
+ case SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_assertion2keys_sub;
+ break;
+ case SLAPI_PLUGIN_MR_FLAGS:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(int *)value) = pblock->pb_plugin->plg_mr_flags;
+ break;
+ case SLAPI_PLUGIN_MR_NAMES:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(char ***)value) = pblock->pb_plugin->plg_mr_names;
+ break;
+ case SLAPI_PLUGIN_MR_COMPARE:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ (*(IFP *)value) = pblock->pb_plugin->plg_mr_compare;
+ break;
+
/* seq arguments */
case SLAPI_SEQ_TYPE:
(*(int *)value) = pblock->pb_seq_type;
@@ -2371,7 +2421,7 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
}
pblock->pb_plugin->plg_syntax_compare = (IFP) value;
break;
- case SLAPI_SYNTAX_SUBSTRLENS:
+ case SLAPI_SYNTAX_SUBSTRLENS: /* aka SLAPI_MR_SUBSTRLENS */
pblock->pb_substrlens = (int *) value;
break;
case SLAPI_PLUGIN_SYNTAX_VALIDATE:
@@ -2699,6 +2749,56 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
pblock->pb_mr_usage = *(unsigned int *) value;
break;
+ /* new style matching rule syntax plugin functions */
+ case SLAPI_PLUGIN_MR_FILTER_AVA:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_filter_ava = (IFP) value;
+ break;
+ case SLAPI_PLUGIN_MR_FILTER_SUB:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_filter_sub = (IFP) value;
+ break;
+ case SLAPI_PLUGIN_MR_VALUES2KEYS:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_values2keys = (IFP) value;
+ break;
+ case SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_assertion2keys_ava = (IFP) value;
+ break;
+ case SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_assertion2keys_sub = (IFP) value;
+ break;
+ case SLAPI_PLUGIN_MR_FLAGS:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_flags = *((int *) value);
+ break;
+ case SLAPI_PLUGIN_MR_NAMES:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_names = (char **) value;
+ break;
+ case SLAPI_PLUGIN_MR_COMPARE:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_MATCHINGRULE ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_mr_compare = (IFP) value;
+ break;
+
/* seq arguments */
case SLAPI_SEQ_TYPE:
pblock->pb_seq_type = *((int *)value);
diff --git a/ldap/servers/slapd/plugin_mr.c b/ldap/servers/slapd/plugin_mr.c
index fc07733c..8f62a7a0 100644
--- a/ldap/servers/slapd/plugin_mr.c
+++ b/ldap/servers/slapd/plugin_mr.c
@@ -65,8 +65,21 @@ slapi_get_global_mr_plugins()
return get_plugin_list(PLUGIN_LIST_MATCHINGRULE);
}
+struct slapdplugin *
+plugin_mr_find( const char *nameoroid )
+{
+ struct slapdplugin *pi;
+
+ for ( pi = get_plugin_list(PLUGIN_LIST_MATCHINGRULE); pi != NULL; pi = pi->plg_next ) {
+ if ( charray_inlist( pi->plg_mr_names, (char *)nameoroid ) ) {
+ break;
+ }
+ }
+ return ( pi );
+}
+
static struct slapdplugin*
-plugin_mr_find (char* oid)
+plugin_mr_find_registered (char* oid)
{
oid_item_t* i;
init_global_mr_lock();
@@ -77,11 +90,11 @@ plugin_mr_find (char* oid)
{
if (!strcasecmp (oid, i->oi_oid))
{
- LDAPDebug (LDAP_DEBUG_FILTER, "plugin_mr_find(%s) != NULL\n", oid, 0, 0);
+ LDAPDebug (LDAP_DEBUG_FILTER, "plugin_mr_find_registered(%s) != NULL\n", oid, 0, 0);
return i->oi_plugin;
}
}
- LDAPDebug (LDAP_DEBUG_FILTER, "plugin_mr_find(%s) == NULL\n", oid, 0, 0);
+ LDAPDebug (LDAP_DEBUG_FILTER, "plugin_mr_find_registered(%s) == NULL\n", oid, 0, 0);
return NULL;
}
@@ -108,7 +121,7 @@ slapi_mr_indexer_create (Slapi_PBlock* opb)
if (!(rc = slapi_pblock_get (opb, SLAPI_PLUGIN_MR_OID, &oid)))
{
IFP createFn = NULL;
- struct slapdplugin* mrp = plugin_mr_find (oid);
+ struct slapdplugin* mrp = plugin_mr_find_registered (oid);
if (mrp != NULL)
{
if (!(rc = slapi_pblock_set (opb, SLAPI_PLUGIN, mrp)) &&
@@ -172,7 +185,7 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
plugin_mr_filter_create (mr_filter_t* f)
{
int rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
- struct slapdplugin* mrp = plugin_mr_find (f->mrf_oid);
+ struct slapdplugin* mrp = plugin_mr_find_registered (f->mrf_oid);
Slapi_PBlock pb;
if (mrp != NULL)
diff --git a/ldap/servers/slapd/plugin_syntax.c b/ldap/servers/slapd/plugin_syntax.c
index e2cc7fb1..80ce12a7 100644
--- a/ldap/servers/slapd/plugin_syntax.c
+++ b/ldap/servers/slapd/plugin_syntax.c
@@ -89,7 +89,10 @@ slapi_get_global_syntax_plugins()
char *
plugin_syntax2oid( struct slapdplugin *pi )
{
- return( pi->plg_syntax_oid );
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "the function plugin_syntax2oid is deprecated - please use attr_get_syntax_oid instead\n", 0, 0, 0);
+ PR_ASSERT(0);
+ return( NULL );
}
int
@@ -98,37 +101,9 @@ plugin_call_syntax_get_compare_fn(
value_compare_fn_type *compare_fn
)
{
- struct slapdplugin *pi = vpi;
- *compare_fn = NULL;
-
- LDAPDebug( LDAP_DEBUG_TRACE,
- "=> plugin_call_syntax_get_compare_fn\n",0,0, 0 );
-
- if ( pi == NULL ) {
- LDAPDebug( LDAP_DEBUG_TRACE,
- "<= plugin_syntax no plugin for attribute type\n",
- 0, 0, 0 );
- return( LDAP_PROTOCOL_ERROR ); /* syntax unkonwn */
- }
-
- if ( (pi->plg_syntax_flags & SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0 ) {
- return( LDAP_PROTOCOL_ERROR );
- }
-
- if (pi->plg_syntax_filter_ava == NULL) {
- LDAPDebug( LDAP_DEBUG_ANY, "<= plugin_call_syntax_get_compare_fn: "
- "no filter_ava found for attribute type\n", 0, 0, 0 );
- return( LDAP_PROTOCOL_ERROR );
- }
-
- if (pi->plg_syntax_compare == NULL) {
- return( LDAP_PROTOCOL_ERROR );
- }
-
- *compare_fn = (value_compare_fn_type) pi->plg_syntax_compare;
-
- LDAPDebug( LDAP_DEBUG_TRACE,
- "<= plugin_call_syntax_get_compare_fn \n", 0, 0, 0 );
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "the function plugin_call_syntax_get_compare_fn is deprecated - please use attr_get_value_cmp_fn instead\n", 0, 0, 0);
+ PR_ASSERT(0);
return( 0 );
}
@@ -153,14 +128,15 @@ plugin_call_syntax_filter_ava_sv(
{
int rc;
Slapi_PBlock pipb;
+ IFP ava_fn = NULL;
LDAPDebug( LDAP_DEBUG_FILTER,
"=> plugin_call_syntax_filter_ava %s=%s\n", ava->ava_type,
ava->ava_value.bv_val, 0 );
- if ( a->a_plugin == NULL ) {
+ if ( ( a->a_mr_eq_plugin == NULL ) && ( a->a_mr_ord_plugin == NULL ) && ( a->a_plugin == NULL ) ) {
LDAPDebug( LDAP_DEBUG_FILTER,
- "<= plugin_syntax no plugin for attr (%s)\n",
+ "<= plugin_call_syntax_filter_ava no plugin for attr (%s)\n",
a->a_type, 0, 0 );
return( LDAP_PROTOCOL_ERROR ); /* syntax unkonwn */
}
@@ -172,33 +148,58 @@ plugin_call_syntax_filter_ava_sv(
switch ( ftype ) {
case LDAP_FILTER_GE:
case LDAP_FILTER_LE:
- if ( (a->a_plugin->plg_syntax_flags &
- SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0 ) {
+ if ((a->a_mr_ord_plugin == NULL) &&
+ ((a->a_plugin->plg_syntax_flags &
+ SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0)) {
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "<= plugin_call_syntax_filter_ava: attr (%s) has no ordering matching rule, and syntax does not define a compare function\n",
+ a->a_type, 0, 0 );
rc = LDAP_PROTOCOL_ERROR;
break;
}
+ /* if the attribute has an ordering matching rule plugin, use that,
+ otherwise, just use the syntax plugin */
+ if (a->a_mr_ord_plugin != NULL) {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_ord_plugin );
+ ava_fn = a->a_mr_ord_plugin->plg_mr_filter_ava;
+ } else {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
+ ava_fn = a->a_plugin->plg_syntax_filter_ava;
+ }
/* FALL */
case LDAP_FILTER_EQUALITY:
case LDAP_FILTER_APPROX:
- if ( a->a_plugin->plg_syntax_filter_ava != NULL )
- {
+ if (NULL == ava_fn) {
+ /* if we have an equality matching rule plugin, use that,
+ otherwise, just use the syntax plugin */
+ if (a->a_mr_eq_plugin) {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_eq_plugin );
+ ava_fn = a->a_mr_eq_plugin->plg_mr_filter_ava;
+ } else {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
+ ava_fn = a->a_plugin->plg_syntax_filter_ava;
+ }
+ }
+
+ if ( ava_fn != NULL ) {
/* JCM - Maybe the plugin should use the attr value iterator too... */
Slapi_Value **va;
- if(useDeletedValues)
+ if(useDeletedValues) {
va= valueset_get_valuearray(&a->a_deleted_values);
- else
+ } else {
va= valueset_get_valuearray(&a->a_present_values);
- if(va!=NULL)
- {
- rc = a->a_plugin->plg_syntax_filter_ava( &pipb,
- &ava->ava_value,
- va,
- ftype, retVal );
}
+ if(va!=NULL) {
+ rc = (*ava_fn)( &pipb, &ava->ava_value, va, ftype, retVal );
+ }
+ } else {
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "<= plugin_call_syntax_filter_ava: attr (%s) has no ava filter function\n",
+ a->a_type, 0, 0 );
}
break;
default:
- LDAPDebug( LDAP_DEBUG_ANY, "plugin_call_syntax_filter: "
+ LDAPDebug( LDAP_DEBUG_ANY, "plugin_call_syntax_filter_ava: "
"unknown filter type %d\n", ftype, 0, 0 );
rc = LDAP_PROTOCOL_ERROR;
break;
@@ -228,20 +229,32 @@ plugin_call_syntax_filter_sub_sv(
{
Slapi_PBlock pipb;
int rc;
+ IFP sub_fn = NULL;
LDAPDebug( LDAP_DEBUG_FILTER,
- "=> plugin_call_syntax_filter_sub\n", 0, 0, 0 );
+ "=> plugin_call_syntax_filter_sub_sv\n", 0, 0, 0 );
- if ( a->a_plugin == NULL ) {
+ if ( ( a->a_mr_sub_plugin == NULL ) && ( a->a_plugin == NULL ) ) {
LDAPDebug( LDAP_DEBUG_FILTER,
- "<= plugin_call_syntax_filter no plugin\n", 0, 0, 0 );
+ "<= plugin_call_syntax_filter_sub_sv attribute (%s) has no substring matching rule or syntax plugin\n",
+ a->a_type, 0, 0 );
return( -1 ); /* syntax unkonwn - does not match */
}
- if ( a->a_plugin->plg_syntax_filter_sub != NULL )
+ pblock_init( &pipb );
+ /* use the substr matching rule plugin if available, otherwise, use
+ the syntax plugin */
+ if (a->a_mr_sub_plugin) {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_mr_sub_plugin );
+ sub_fn = a->a_mr_sub_plugin->plg_mr_filter_sub;
+ } else {
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
+ sub_fn = a->a_plugin->plg_syntax_filter_sub;
+ }
+
+ if ( sub_fn != NULL )
{
Slapi_Value **va= valueset_get_valuearray(&a->a_present_values);
- pblock_init( &pipb );
if (pb)
{
Operation *op = NULL;
@@ -249,9 +262,7 @@ plugin_call_syntax_filter_sub_sv(
slapi_pblock_get( pb, SLAPI_OPERATION, &op );
slapi_pblock_set( &pipb, SLAPI_OPERATION, op );
}
- slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
- rc = a->a_plugin->plg_syntax_filter_sub( &pipb,
- fsub->sf_initial, fsub->sf_any, fsub->sf_final, va);
+ rc = (*sub_fn)( &pipb, fsub->sf_initial, fsub->sf_any, fsub->sf_final, va);
} else {
rc = -1;
}
@@ -554,6 +565,95 @@ slapi_call_syntax_values2keys_sv(
return( rc );
}
+int
+slapi_attr_values2keys_sv_pb(
+ const Slapi_Attr *sattr,
+ Slapi_Value **vals,
+ Slapi_Value ***ivals,
+ int ftype,
+ Slapi_PBlock *pb
+)
+{
+ int rc;
+ struct slapdplugin *pi = NULL;
+ IFP v2k_fn = NULL;
+
+ LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_attr_values2keys_sv\n",
+ 0, 0, 0 );
+
+ switch (ftype) {
+ case LDAP_FILTER_EQUALITY:
+ case LDAP_FILTER_APPROX:
+ if (sattr->a_mr_eq_plugin) {
+ pi = sattr->a_mr_eq_plugin;
+ v2k_fn = sattr->a_mr_eq_plugin->plg_mr_values2keys;
+ } else if (sattr->a_plugin) {
+ pi = sattr->a_plugin;
+ v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
+ }
+ break;
+ case LDAP_FILTER_SUBSTRINGS:
+ if (sattr->a_mr_sub_plugin) {
+ pi = sattr->a_mr_sub_plugin;
+ v2k_fn = sattr->a_mr_sub_plugin->plg_mr_values2keys;
+ } else if (sattr->a_plugin) {
+ pi = sattr->a_plugin;
+ v2k_fn = sattr->a_plugin->plg_syntax_values2keys;
+ }
+ break;
+ default:
+ LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_values2keys_sv: ERROR: unsupported filter type %d\n",
+ ftype, 0, 0 );
+ rc = LDAP_PROTOCOL_ERROR;
+ goto done;
+ }
+
+ slapi_pblock_set( pb, SLAPI_PLUGIN, pi );
+
+ *ivals = NULL;
+ rc = -1; /* means no values2keys function */
+ if ( ( pi != NULL ) && ( v2k_fn != NULL ) ) {
+ rc = (*v2k_fn)( pb, vals, ivals, ftype );
+ }
+
+done:
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
+ return( rc );
+}
+
+int
+slapi_attr_values2keys_sv(
+ const Slapi_Attr *sattr,
+ Slapi_Value **vals,
+ Slapi_Value ***ivals,
+ int ftype
+)
+{
+ Slapi_PBlock pb;
+ pblock_init(&pb);
+ return slapi_attr_values2keys_sv_pb(sattr, vals, ivals, ftype, &pb);
+}
+
+SLAPI_DEPRECATED int
+slapi_attr_values2keys( /* JCM SLOW FUNCTION */
+ const Slapi_Attr *sattr,
+ struct berval **vals,
+ struct berval ***ivals,
+ int ftype
+)
+{
+ int rc;
+ Slapi_Value **svin= NULL;
+ Slapi_Value **svout= NULL;
+ valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
+ rc= slapi_attr_values2keys_sv(sattr,svin,&svout,ftype);
+ valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
+ valuearray_free(&svout);
+ valuearray_free(&svin);
+ return rc;
+}
+
/*
* almost identical to slapi_call_syntax_values2keys_sv except accepting
* pblock to pass some info such as substrlen.
@@ -633,6 +733,73 @@ slapi_call_syntax_assertion2keys_ava_sv(
return( rc );
}
+int
+slapi_attr_assertion2keys_ava_sv(
+ const Slapi_Attr *sattr,
+ Slapi_Value *val,
+ Slapi_Value ***ivals,
+ int ftype
+)
+{
+ int rc;
+ Slapi_PBlock pipb;
+ struct slapdplugin *pi = NULL;
+ IFP a2k_fn = NULL;
+
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "=> slapi_attr_assertion2keys_ava_sv\n", 0, 0, 0 );
+
+ switch (ftype) {
+ case LDAP_FILTER_EQUALITY:
+ case LDAP_FILTER_APPROX:
+ case LDAP_FILTER_EQUALITY_FAST:
+ if (sattr->a_mr_eq_plugin) {
+ pi = sattr->a_mr_eq_plugin;
+ a2k_fn = sattr->a_mr_eq_plugin->plg_mr_assertion2keys_ava;
+ } else if (sattr->a_plugin) {
+ pi = sattr->a_plugin;
+ a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_ava;
+ }
+ break;
+ default:
+ LDAPDebug( LDAP_DEBUG_ANY, "<= slapi_attr_assertion2keys_ava_sv: ERROR: unsupported filter type %d\n",
+ ftype, 0, 0 );
+ rc = LDAP_PROTOCOL_ERROR;
+ goto done;
+ }
+
+ pblock_init( &pipb );
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
+
+ rc = -1; /* means no assertion2keys function */
+ if ( a2k_fn != NULL ) {
+ rc = (*a2k_fn)( &pipb, val, ivals, ftype );
+ }
+done:
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "<= slapi_attr_assertion2keys_ava_sv %d\n", rc, 0, 0 );
+ return( rc );
+}
+
+SLAPI_DEPRECATED int
+slapi_attr_assertion2keys_ava( /* JCM SLOW FUNCTION */
+ const Slapi_Attr *sattr,
+ struct berval *val,
+ struct berval ***ivals,
+ int ftype
+)
+{
+ int rc;
+ Slapi_Value svin;
+ Slapi_Value **svout= NULL;
+ slapi_value_init_berval(&svin, val);
+ rc= slapi_attr_assertion2keys_ava_sv(sattr,&svin,&svout,ftype);
+ valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
+ valuearray_free(&svout);
+ value_done(&svin);
+ return rc;
+}
+
SLAPI_DEPRECATED int
slapi_call_syntax_assertion2keys_sub( /* JCM SLOW FUNCTION */
void *vpi,
@@ -681,3 +848,57 @@ slapi_call_syntax_assertion2keys_sub_sv(
return( rc );
}
+int
+slapi_attr_assertion2keys_sub_sv(
+ const Slapi_Attr *sattr,
+ char *initial,
+ char **any,
+ char *final,
+ Slapi_Value ***ivals
+)
+{
+ int rc;
+ Slapi_PBlock pipb;
+ struct slapdplugin *pi = NULL;
+ IFP a2k_fn = NULL;
+
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "=> slapi_attr_assertion2keys_sub_sv\n", 0, 0, 0 );
+
+ if (sattr->a_mr_sub_plugin) {
+ pi = sattr->a_mr_sub_plugin;
+ a2k_fn = sattr->a_mr_sub_plugin->plg_mr_assertion2keys_sub;
+ } else if (sattr->a_plugin) {
+ pi = sattr->a_plugin;
+ a2k_fn = sattr->a_plugin->plg_syntax_assertion2keys_sub;
+ }
+ pblock_init( &pipb );
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN, pi );
+
+ rc = -1; /* means no assertion2keys function */
+ *ivals = NULL;
+ if ( a2k_fn != NULL ) {
+ rc = (*a2k_fn)( &pipb, initial, any, final, ivals );
+ }
+
+ LDAPDebug( LDAP_DEBUG_FILTER,
+ "<= slapi_attr_assertion2keys_sub_sv %d\n", rc, 0, 0 );
+ return( rc );
+}
+
+SLAPI_DEPRECATED int
+slapi_attr_assertion2keys_sub( /* JCM SLOW FUNCTION */
+ const Slapi_Attr *sattr,
+ char *initial,
+ char **any,
+ char *final,
+ struct berval ***ivals
+)
+{
+ int rc;
+ Slapi_Value **svout= NULL;
+ rc= slapi_attr_assertion2keys_sub_sv(sattr,initial,any,final,&svout);
+ valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
+ valuearray_free(&svout);
+ return rc;
+}
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index feca39a6..9133958c 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -69,6 +69,27 @@ int attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn);
int attr_replace(Slapi_Attr *a, Slapi_Value **vals);
int attr_check_onoff ( const char *attr_name, char *value, long minval, long maxval, char *errorbuf );
int attr_check_minmax ( const char *attr_name, char *value, long minval, long maxval, char *errorbuf );
+/**
+ * Returns the function which can be used to compare (like memcmp/strcmp)
+ * two values of this type of attribute. The comparison function will use
+ * the ORDERING matching rule if available, or the default comparison
+ * function from the syntax plugin.
+ * Note: if there is no ORDERING matching rule, and the syntax does not
+ * provide an ordered compare function, this function will return
+ * LDAP_PROTOCOL_ERROR and compare_fn will be NULL.
+ * Returns LDAP_SUCCESS if successful and sets *compare_fn to the function.
+ *
+ * \param attr The attribute to use
+ * \param compare_fn address of function pointer to set to the function to use
+ * \return LDAP_SUCCESS - success
+ * LDAP_PARAM_ERROR - attr is NULL
+ * LDAP_PROTOCOL_ERROR - attr does not support an ordering compare function
+ * \see value_compare_fn_type
+ */
+int attr_get_value_cmp_fn(const Slapi_Attr *attr, value_compare_fn_type *compare_fn);
+/* return the OID of the syntax for this attribute */
+const char *attr_get_syntax_oid(const Slapi_Attr *attr);
+
/*
* attrlist.c
@@ -145,8 +166,8 @@ void valuearrayfast_add_value(struct valuearrayfast *vaf,const Slapi_Value *v);
void valuearrayfast_add_value_passin(struct valuearrayfast *vaf,Slapi_Value *v);
void valuearrayfast_add_valuearrayfast(struct valuearrayfast *vaf,const struct valuearrayfast *vaf_add);
-int valuetree_add_value( const char *type, struct slapdplugin *pi, const Slapi_Value *va, Avlnode **valuetreep);
-int valuetree_add_valuearray( const char *type, struct slapdplugin *pi, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index);
+int valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *va, Avlnode **valuetreep);
+int valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index);
void valuetree_free( Avlnode **valuetreep );
/* Valueset functions */
@@ -779,6 +800,7 @@ void plugin_print_lists(void);
*/
struct slapdplugin *slapi_get_global_mr_plugins();
int plugin_mr_filter_create (mr_filter_t* f);
+struct slapdplugin *plugin_mr_find( const char *nameoroid );
/*
* plugin_syntax.c
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
index 98224df6..dadc307d 100644
--- a/ldap/servers/slapd/schema.c
+++ b/ldap/servers/slapd/schema.c
@@ -1180,7 +1180,7 @@ schema_attr_enum_callback(struct asyntaxinfo *asip, void *arg)
}
}
- syntaxoid = plugin_syntax2oid(asip->asi_plugin);
+ syntaxoid = asip->asi_plugin->plg_syntax_oid;
if ( !aew->schema_ds4x_compat &&
asip->asi_syntaxlength != SLAPI_SYNTAXLENGTH_NONE ) {
@@ -3410,7 +3410,7 @@ read_at_ldif(const char *input, struct asyntaxinfo **asipp, char *errorbuf,
/* We only want to use the parent syntax if a SYNTAX
* wasn't explicitly specified for this attribute. */
} else if (NULL == pSyntax) {
- char *pso = plugin_syntax2oid(asi_parent->asi_plugin);
+ char *pso = asi_parent->asi_plugin->plg_syntax_oid;
if (pso) {
slapi_ch_free ((void **)&pSyntax);
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index 08de2c15..9dea4525 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -453,11 +453,14 @@ struct slapi_attr {
char *a_type;
struct slapi_value_set a_present_values;
unsigned long a_flags; /* SLAPI_ATTR_FLAG_... */
- struct slapdplugin *a_plugin;
+ struct slapdplugin *a_plugin; /* for the attribute syntax */
struct slapi_value_set a_deleted_values;
struct bervals2free *a_listtofree; /* JCM: EVIL... For DS4 Slapi compatibility. */
struct slapi_attr *a_next;
CSN *a_deletioncsn; /* The point in time at which this attribute was last deleted */
+ struct slapdplugin *a_mr_eq_plugin; /* for the attribute EQUALITY matching rule, if any */
+ struct slapdplugin *a_mr_ord_plugin; /* for the attribute ORDERING matching rule, if any */
+ struct slapdplugin *a_mr_sub_plugin; /* for the attribute SUBSTRING matching rule, if any */
};
typedef struct oid_item {
@@ -482,6 +485,9 @@ typedef struct asyntaxinfo {
int asi_syntaxlength; /* length associated w/syntax */
int asi_refcnt; /* outstanding references */
PRBool asi_marked_for_delete; /* delete at next opportunity */
+ struct slapdplugin *asi_mr_eq_plugin; /* EQUALITY matching rule plugin */
+ struct slapdplugin *asi_mr_sub_plugin; /* SUBSTR matching rule plugin */
+ struct slapdplugin *asi_mr_ord_plugin; /* ORDERING matching rule plugin */
} asyntaxinfo;
/*
@@ -982,9 +988,28 @@ struct slapdplugin {
struct plg_un_matching_rule {
IFP plg_un_mr_filter_create; /* factory function */
IFP plg_un_mr_indexer_create; /* factory function */
+ /* new style syntax plugin functions */
+ /* not all functions will apply to all matching rule types */
+ /* e.g. a SUBSTR rule will not have a filter_ava func */
+ IFP plg_un_mr_filter_ava;
+ IFP plg_un_mr_filter_sub;
+ IFP plg_un_mr_values2keys;
+ IFP plg_un_mr_assertion2keys_ava;
+ IFP plg_un_mr_assertion2keys_sub;
+ int plg_un_mr_flags;
+ char **plg_un_mr_names;
+ IFP plg_un_mr_compare; /* only for ORDERING */
} plg_un_mr;
#define plg_mr_filter_create plg_un.plg_un_mr.plg_un_mr_filter_create
#define plg_mr_indexer_create plg_un.plg_un_mr.plg_un_mr_indexer_create
+#define plg_mr_filter_ava plg_un.plg_un_mr.plg_un_mr_filter_ava
+#define plg_mr_filter_sub plg_un.plg_un_mr.plg_un_mr_filter_sub
+#define plg_mr_values2keys plg_un.plg_un_mr.plg_un_mr_values2keys
+#define plg_mr_assertion2keys_ava plg_un.plg_un_mr.plg_un_mr_assertion2keys_ava
+#define plg_mr_assertion2keys_sub plg_un.plg_un_mr.plg_un_mr_assertion2keys_sub
+#define plg_mr_flags plg_un.plg_un_mr.plg_un_mr_flags
+#define plg_mr_names plg_un.plg_un_mr.plg_un_mr_names
+#define plg_mr_compare plg_un.plg_un_mr.plg_un_mr_compare
/* syntax plugin structure */
struct plg_un_syntax_struct {
diff --git a/ldap/servers/slapd/slapi-plugin-compat4.h b/ldap/servers/slapd/slapi-plugin-compat4.h
index d54cc7d1..17f35260 100644
--- a/ldap/servers/slapd/slapi-plugin-compat4.h
+++ b/ldap/servers/slapd/slapi-plugin-compat4.h
@@ -106,6 +106,12 @@ SLAPI_DEPRECATED int slapi_call_syntax_assertion2keys_ava( void *vpi,
struct berval *val, struct berval ***ivals, int ftype );
SLAPI_DEPRECATED int slapi_call_syntax_assertion2keys_sub( void *vpi,
char *initial, char **any, char *final, struct berval ***ivals );
+SLAPI_DEPRECATED int slapi_attr_values2keys( const Slapi_Attr *sattr,
+ struct berval **vals, struct berval ***ivals, int ftype );
+SLAPI_DEPRECATED int slapi_attr_assertion2keys_ava( const Slapi_Attr *sattr,
+ struct berval *val, struct berval ***ivals, int ftype );
+SLAPI_DEPRECATED int slapi_attr_assertion2keys_sub( const Slapi_Attr *sattr,
+ char *initial, char **any, char *final, struct berval ***ivals );
/*
* slapi_entry_attr_hasvalue() has been deprecated in favor of
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index 09cc9d46..6ced381e 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -3263,6 +3263,11 @@ int slapi_attr_add_value(Slapi_Attr *a, const Slapi_Value *v);
* \param pi Address to receive a pointer to the plugin structure.
* \return \c 0 if successful.
* \return \c -1 if the plugin is not found.
+ * \deprecated This function was necessary in order to call syntax plugin
+ * filter and indexing functions - there are new functions
+ * to use instead, such as slapi_attr_values2keys, etc.
+ * This function is still used by internal APIs, but new
+ * code should not use this function
* \see slapi_attr_get_type()
* \see slapi_attr_type_cmp()
* \see slapi_attr_types_equivalent()
@@ -3586,7 +3591,6 @@ int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals );
*/
char * slapi_attr_syntax_normalize( const char *s );
-
/*
* value routines
*/
@@ -4726,6 +4730,9 @@ char * slapi_ch_smprintf(const char *fmt, ...)
/*
* syntax plugin routines
+ * THESE ARE DEPRECATED - the first argument is the syntax plugin
+ * we do not support that style of call anymore - use the slapi_attr_
+ * versions below instead
*/
int slapi_call_syntax_values2keys_sv( void *vpi, Slapi_Value **vals,
Slapi_Value ***ivals, int ftype );
@@ -4736,6 +4743,15 @@ int slapi_call_syntax_assertion2keys_ava_sv( void *vpi, Slapi_Value *val,
int slapi_call_syntax_assertion2keys_sub_sv( void *vpi, char *initial,
char **any, char *final, Slapi_Value ***ivals );
+int slapi_attr_values2keys_sv( const Slapi_Attr *sattr, Slapi_Value **vals,
+ Slapi_Value ***ivals, int ftype );
+int slapi_attr_values2keys_sv_pb( const Slapi_Attr *sattr, Slapi_Value **vals,
+ Slapi_Value ***ivals, int ftype, Slapi_PBlock *pb );
+int slapi_attr_assertion2keys_ava_sv( const Slapi_Attr *sattr, Slapi_Value *val,
+ Slapi_Value ***ivals, int ftype );
+int slapi_attr_assertion2keys_sub_sv( const Slapi_Attr *sattr, char *initial,
+ char **any, char *final, Slapi_Value ***ivals );
+
/*
* internal operation and plugin callback routines
@@ -5450,7 +5466,15 @@ typedef struct slapi_plugindesc {
#define SLAPI_PLUGIN_MR_FILTER_REUSABLE 615
#define SLAPI_PLUGIN_MR_QUERY_OPERATOR 616
#define SLAPI_PLUGIN_MR_USAGE 617
-
+/* new style matching rule syntax plugin functions */
+#define SLAPI_PLUGIN_MR_FILTER_AVA 618
+#define SLAPI_PLUGIN_MR_FILTER_SUB 619
+#define SLAPI_PLUGIN_MR_VALUES2KEYS 620
+#define SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA 621
+#define SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB 622
+#define SLAPI_PLUGIN_MR_FLAGS 623
+#define SLAPI_PLUGIN_MR_NAMES 624
+#define SLAPI_PLUGIN_MR_COMPARE 625
/* Defined values of SLAPI_PLUGIN_MR_QUERY_OPERATOR: */
#define SLAPI_OP_LESS 1
@@ -5484,6 +5508,7 @@ typedef struct slapi_plugindesc {
/* user defined substrlen; not stored in slapdplugin, but pblock itself */
#define SLAPI_SYNTAX_SUBSTRLENS 709
+#define SLAPI_MR_SUBSTRLENS SLAPI_SYNTAX_SUBSTRLENS /* alias */
#define SLAPI_PLUGIN_SYNTAX_VALIDATE 710
/* ACL plugin functions and arguments */
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
index 7334a7a0..a9cd37ee 100644
--- a/ldap/servers/slapd/valueset.c
+++ b/ldap/servers/slapd/valueset.c
@@ -616,12 +616,11 @@ typedef struct valuetree_node
* and *valuetreep is set to NULL.
*/
int
-valuetree_add_valuearray( const char *type, struct slapdplugin *pi, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index )
+valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index )
{
int rc= LDAP_SUCCESS;
- PR_ASSERT(type!=NULL);
- PR_ASSERT(pi!=NULL);
+ PR_ASSERT(sattr!=NULL);
PR_ASSERT(valuetreep!=NULL);
if ( duplicate_index ) {
@@ -632,9 +631,9 @@ valuetree_add_valuearray( const char *type, struct slapdplugin *pi, Slapi_Value
{
Slapi_Value **keyvals;
/* Convert the value array into key values */
- if ( slapi_call_syntax_values2keys_sv( pi, (Slapi_Value**)va, &keyvals, LDAP_FILTER_EQUALITY ) != 0 ) /* jcm cast */
+ if ( slapi_attr_values2keys_sv( sattr, (Slapi_Value**)va, &keyvals, LDAP_FILTER_EQUALITY ) != 0 ) /* jcm cast */
{
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_call_syntax_values2keys for attribute %s failed\n", type, 0, 0 );
+ LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s failed\n", sattr->a_type, 0, 0 );
rc= LDAP_OPERATIONS_ERROR;
}
else
@@ -645,7 +644,7 @@ valuetree_add_valuearray( const char *type, struct slapdplugin *pi, Slapi_Value
{
if ( keyvals[i] == NULL )
{
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_call_syntax_values2keys for attribute %s did not return enough key values\n", type, 0, 0 );
+ LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s did not return enough key values\n", sattr->a_type, 0, 0 );
rc= LDAP_OPERATIONS_ERROR;
}
else
@@ -685,12 +684,12 @@ valuetree_add_valuearray( const char *type, struct slapdplugin *pi, Slapi_Value
}
int
-valuetree_add_value( const char *type, struct slapdplugin *pi, const Slapi_Value *v, Avlnode **valuetreep)
+valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *v, Avlnode **valuetreep)
{
Slapi_Value *va[2];
va[0]= (Slapi_Value*)v;
va[1]= NULL;
- return valuetree_add_valuearray( type, pi, va, valuetreep, NULL);
+ return valuetree_add_valuearray( sattr, va, valuetreep, NULL);
}
@@ -714,7 +713,7 @@ valuetree_find( const struct slapi_attr *a, const Slapi_Value *v, Avlnode *value
PR_ASSERT(valuetree!=NULL);
PR_ASSERT(index!=NULL);
- if ( a == NULL || a->a_plugin == NULL || v == NULL || valuetree == NULL )
+ if ( a == NULL || v == NULL || valuetree == NULL )
{
return( LDAP_OPERATIONS_ERROR );
}
@@ -722,12 +721,12 @@ valuetree_find( const struct slapi_attr *a, const Slapi_Value *v, Avlnode *value
keyvals = NULL;
oneval[0] = v;
oneval[1] = NULL;
- if ( slapi_call_syntax_values2keys_sv( a->a_plugin, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0 /* jcm cast */
+ if ( slapi_attr_values2keys_sv( a, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0 /* jcm cast */
|| keyvals == NULL
|| keyvals[0] == NULL )
{
LDAPDebug( LDAP_DEBUG_ANY, "valuetree_find_and_replace: "
- "slapi_call_syntax_values2keys failed for type %s\n",
+ "slapi_attr_values2keys_sv failed for type %s\n",
a->a_type, 0, 0 );
return( LDAP_OPERATIONS_ERROR );
}
@@ -1104,7 +1103,7 @@ valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value
*/
Avlnode *vtree = NULL;
int numberofexistingvalues= slapi_valueset_count(vs);
- rc= valuetree_add_valuearray( a->a_type, a->a_plugin, vs->va, &vtree, NULL );
+ rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
if ( rc!=LDAP_SUCCESS )
{
/*
@@ -1286,14 +1285,14 @@ valueset_intersectswith_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slap
* Several values to add: use an AVL tree to detect duplicates.
*/
Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray( a->a_type, a->a_plugin, vs->va, &vtree, duplicate_index );
+ rc= valuetree_add_valuearray( a, vs->va, &vtree, duplicate_index );
if(rc==LDAP_OPERATIONS_ERROR)
{
/* There were already duplicate values in the value set */
}
else
{
- rc= valuetree_add_valuearray( a->a_type, a->a_plugin, values, &vtree, duplicate_index );
+ rc= valuetree_add_valuearray( a, values, &vtree, duplicate_index );
/*
* Returns LDAP_OPERATIONS_ERROR if something very bad happens.
* Or LDAP_TYPE_OR_VALUE_EXISTS if a value already exists.
@@ -1356,7 +1355,7 @@ valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
if (numberofvalstoreplace > 1)
{
Avlnode *vtree = NULL;
- rc = valuetree_add_valuearray( a->a_type, a->a_plugin, valstoreplace, &vtree, NULL );
+ rc = valuetree_add_valuearray( a, valstoreplace, &vtree, NULL );
valuetree_free(&vtree);
if ( LDAP_SUCCESS != rc &&
/* bz 247413: don't override LDAP_TYPE_OR_VALUE_EXISTS */
@@ -1396,7 +1395,7 @@ valueset_update_csn_for_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slap
{
int i;
Avlnode *vtree = NULL;
- int rc= valuetree_add_valuearray( a->a_type, a->a_plugin, vs->va, &vtree, NULL );
+ int rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
PR_ASSERT(rc==LDAP_SUCCESS);
for (i=0;valuestoupdate[i]!=NULL;++i)
{