]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/index.c
Code clean-up.
[openldap] / servers / slapd / back-ldbm / index.c
index 100b058b735674991d6e74d96c9fe96a3d08166f..0d595119c693d912dc4be00fc6fc9b95af80d9e2 100644 (file)
@@ -1,23 +1,17 @@
 /* index.c - routines for dealing with attribute indexes */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
-#include "back-ldbm.h"
 
-extern char            *first_word();
-extern char            *next_word();
-extern char            *phonetic();
-extern IDList          *idl_fetch();
-extern IDList          *idl_allids();
-extern struct dbcache  *ldbm_cache_open();
+#include <ac/string.h>
+#include <ac/socket.h>
 
-int    index_add_values();
+#include "slap.h"
+#include "back-ldbm.h"
 
-static int     add_value();
-static int     index2prefix();
+static int     add_value(Backend *be, struct dbcache *db, char *type, int indextype, char *val, ID id);
+static int     index2prefix(int indextype);
 
 int
 index_add_entry(
@@ -38,7 +32,7 @@ index_add_entry(
         * with index_add_values() call
         */
 
-       bv.bv_val = strdup( e->e_dn );
+       bv.bv_val = ch_strdup( e->e_dn );
        bv.bv_len = strlen( bv.bv_val );
        (void) dn_normalize_case( bv.bv_val );
        bvals[0] = &bv;
@@ -62,18 +56,20 @@ index_add_entry(
 int
 index_add_mods(
     Backend    *be,
-    LDAPMod    *mods,
+    LDAPModList        *ml,
     ID         id
 )
 {
        int     rc;
 
-       for ( ; mods != NULL; mods = mods->mod_next ) {
-               switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
+       for ( ; ml != NULL; ml = ml->ml_next ) {
+               LDAPMod *mod = &ml->ml_mod;
+
+               switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
                case LDAP_MOD_ADD:
                case LDAP_MOD_REPLACE:
-                       rc = index_add_values( be, mods->mod_type,
-                           mods->mod_bvalues, id );
+                       rc = index_add_values( be, mod->mod_type,
+                           mod->mod_bvalues, id );
                        break;
 
                case LDAP_MOD_DELETE:
@@ -89,7 +85,7 @@ index_add_mods(
        return( 0 );
 }
 
-IDList *
+ID_BLOCK *
 index_read(
     Backend    *be,
     char       *type,
@@ -99,12 +95,14 @@ index_read(
 {
        struct dbcache  *db;
        Datum           key;
-       IDList          *idl;
+       ID_BLOCK                *idl;
        int             indexmask, syntax;
        char            prefix;
        char            *realval, *tmpval;
        char            buf[BUFSIZ];
 
+       ldbm_datum_init( key );
+
        prefix = index2prefix( indextype );
        Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n",
            type, prefix, val );
@@ -113,8 +111,8 @@ index_read(
        if ( ! (indextype & indexmask) ) {
                idl =  idl_allids( be );
                Debug( LDAP_DEBUG_TRACE,
-                   "<= index_read %d candidates (allids - not indexed)\n",
-                   idl ? idl->b_nids : 0, 0, 0 );
+                   "<= index_read %ld candidates (allids - not indexed)\n",
+                   idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
                return( idl );
        }
 
@@ -129,8 +127,8 @@ index_read(
 
        realval = val;
        tmpval = NULL;
-       if ( prefix != '\0' ) {
-              int     len = strlen( val );
+       if ( prefix != UNKNOWN_PREFIX ) {
+              unsigned int     len = strlen( val );
 
               if ( (len + 2) < sizeof(buf) ) {
                        realval = buf;
@@ -153,8 +151,8 @@ index_read(
 
        ldbm_cache_close( be, db );
 
-       Debug( LDAP_DEBUG_TRACE, "<= index_read %d candidates\n",
-           idl ? idl->b_nids : 0, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
+           idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
        return( idl );
 }
 
@@ -170,19 +168,19 @@ add_value(
 {
        int     rc;
        Datum   key;
-       IDList  *idl;
-       char    prefix;
-       char    *realval, *tmpval, *s;
+       ID_BLOCK        *idl = NULL;
+       char    *tmpval = NULL;
+       char    *realval = val;
        char    buf[BUFSIZ];
 
-       prefix = index2prefix( indextype );
+       char    prefix = index2prefix( indextype );
+
+       ldbm_datum_init( key );
+
        Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 );
 
-       realval = val;
-       tmpval = NULL;
-       idl = NULL;
-       if ( prefix != '\0' ) {
-              int     len = strlen( val );
+       if ( prefix != UNKNOWN_PREFIX ) {
+              unsigned int     len = strlen( val );
 
               if ( (len + 2) < sizeof(buf) ) {
                        realval = buf;
@@ -203,9 +201,12 @@ add_value(
        if ( tmpval != NULL ) {
                free( tmpval );
        }
-       idl_free( idl );
 
-       pthread_yield();
+       if( idl != NULL ) {
+               idl_free( idl );
+       }
+
+       ldap_pvt_thread_yield();
 
        /* Debug( LDAP_DEBUG_TRACE, "<= add_value %d\n", rc, 0, 0 ); */
        return( rc );
@@ -220,7 +221,7 @@ index_add_values(
 )
 {
        char            *val, *p, *code, *w;
-       int             i, j, len;
+       unsigned        i, j, len;
        int             indexmask, syntax;
        char            buf[SUBLEN + 1];
        char            vbuf[BUFSIZ];
@@ -355,7 +356,7 @@ index2prefix( int indextype )
                prefix = SUB_PREFIX;
                break;
        default:
-               prefix = '\0';
+               prefix = UNKNOWN_PREFIX;
                break;
        }