]> git.sur5r.net Git - openldap/commitdiff
Convert backendInfo/backendDB to STAILQs
authorHoward Chu <hyc@openldap.org>
Thu, 24 Mar 2005 05:13:31 +0000 (05:13 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 24 Mar 2005 05:13:31 +0000 (05:13 +0000)
14 files changed:
servers/slapd/abandon.c
servers/slapd/acl.c
servers/slapd/back-monitor/backend.c
servers/slapd/back-monitor/database.c
servers/slapd/back-monitor/overlay.c
servers/slapd/backend.c
servers/slapd/backover.c
servers/slapd/bconfig.c
servers/slapd/cancel.c
servers/slapd/config.h
servers/slapd/overlays/glue.c
servers/slapd/root_dse.c
servers/slapd/slap.h
servers/slapd/slapcommon.c

index efc3ba7c8e88c9ad69b7f480b30c484ef87d3973..95df80c2a59acc708742e04a7f7d029c6d032478 100644 (file)
@@ -108,10 +108,7 @@ do_abandon( Operation *op, SlapReply *rs )
 int
 fe_op_abandon( Operation *op, SlapReply *rs )
 {
-       int i;
-
-       for ( i = 0; i < nbackends; i++ ) {
-               op->o_bd = &backends[i];
+       LDAP_STAILQ_FOREACH( op->o_bd, &backendDB, be_next ) {
                if ( op->o_bd->be_abandon ) {
                        (void)op->o_bd->be_abandon( op, rs );
                }
index fdb2b9156f6781f49d9bba493699b5dbcfb2c2b7..2c5551cc3f460e2a12a2e3699af1f29e25145dd0 100644 (file)
@@ -223,7 +223,7 @@ access_allowed_mask(
 
        be = op->o_bd;
        if ( be == NULL ) {
-               be = &backends[0];
+               be = LDAP_STAILQ_FIRST(&backendDB);
                be_null = 1;
 #ifdef LDAP_DEVEL
                /*
@@ -1725,7 +1725,7 @@ acl_check_modlist(
 
        be = op->o_bd;
        if ( be == NULL ) {
-               be = &backends[0];
+               be = LDAP_STAILQ_FIRST(&backendDB);
                be_null = 1;
                op->o_bd = be;
        }
index d21582179102b764b365c610a81afb0f8b72abc4..b9e608435807ae3a4d5a91e72e354e51999cbb6f 100644 (file)
@@ -42,6 +42,7 @@ monitor_subsys_backend_init(
        int                     i;
        monitor_entry_t         *mp;
        monitor_subsys_t        *ms_database;
+       BackendInfo                     *bi;
 
        mi = ( monitor_info_t * )be->be_private;
 
@@ -69,14 +70,15 @@ monitor_subsys_backend_init(
        mp->mp_children = NULL;
        ep = &mp->mp_children;
 
-       for ( i = 0; i < nBackendInfo; i++ ) {
+       i = -1;
+       LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
                char            buf[ BACKMONITOR_BUFSIZE ];
-               BackendInfo     *bi;
+               BackendDB               *be;
                struct berval   bv;
                int             j;
                Entry           *e;
 
-               bi = &backendInfo[ i ];
+               i++;
 
                snprintf( buf, sizeof( buf ),
                                "dn: cn=Backend %d,%s\n"
@@ -124,11 +126,13 @@ monitor_subsys_backend_init(
                        }
                }
 
-               for ( j = 0; j < nBackendDB; j++ ) {
-                       BackendDB       *be = &backendDB[ j ];
+               j = -1;
+               LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
                        char            buf[ SLAP_LDAPDN_MAXLEN ];
                        struct berval   dn;
                        
+                       j++;
+
                        if ( be->bd_info != bi ) {
                                continue;
                        }
index 5acedec8ca62d38c332a522293caba376e9d25bf..1deed07e7d9e17914984b478ab8c9bafe31cf8cd 100644 (file)
@@ -166,14 +166,15 @@ monitor_subsys_database_init(
        mp->mp_children = NULL;
        ep = &mp->mp_children;
 
-       for ( i = 0; i < nBackendDB; i++ ) {
+       i = -1;
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
                char            buf[ BACKMONITOR_BUFSIZE ];
                int             j;
                slap_overinfo   *oi = NULL;
-               BackendInfo     *bi;
+               BackendInfo     *bi, *bi2;
                Entry           *e;
 
-               be = &backendDB[ i ];
+               i++;
 
                bi = be->bd_info;
 
@@ -356,8 +357,10 @@ monitor_subsys_database_init(
                }
 #endif /* defined(SLAPD_LDAP) */
 
-               for ( j = 0; j < nBackendInfo; j++ ) {
-                       if ( backendInfo[ j ].bi_type == bi->bi_type ) {
+               j = -1;
+               LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) {
+                       j++;
+                       if ( bi2->bi_type == bi->bi_type ) {
                                struct berval           bv;
 
                                snprintf( buf, sizeof( buf ), 
@@ -550,8 +553,11 @@ monitor_subsys_database_modify(
        if ( n < 0 || n >= nBackendDB )
                return LDAP_NO_SUCH_OBJECT;
 
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( n == 0 ) break;
+               n--;
+       }
        /* do not allow some changes on back-monitor (needs work)... */
-       be = &backendDB[ n ];
        if ( SLAP_MONITOR( be ) )
                return LDAP_UNWILLING_TO_PERFORM;
                
index b90fc8a2b0a0623758370bf45effe0aee8293e9c..c68d5152cd83321faaa4d24c83ab0b96cc9186ab 100644 (file)
@@ -73,6 +73,7 @@ monitor_subsys_overlay_init(
                struct berval   bv;
                int             j;
                Entry           *e;
+               BackendDB       *be;
 
                snprintf( buf, sizeof( buf ),
                                "dn: cn=Overlay %d,%s\n"
@@ -110,11 +111,12 @@ monitor_subsys_overlay_init(
                attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo,
                                &bv, NULL );
 
-               for ( j = 0; j < nBackendDB; j++ ) {
-                       BackendDB       *be = &backendDB[ j ];
+               j = -1;
+               LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
                        char            buf[ SLAP_LDAPDN_MAXLEN ];
                        struct berval   dn;
 
+                       j++;
                        if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) {
                                continue;
                        }
index 1a0277f25cd89f1d3b1785864e436150629570d2..ea42a39d0a06e4dcf45859ec44a939169cfa3600 100644 (file)
@@ -57,10 +57,10 @@ static void call_group_postop_plugins( Operation *op );
  */
 
 int                    nBackendInfo = 0;
-BackendInfo            *backendInfo = NULL;
+slap_bi_head backendInfo = LDAP_STAILQ_HEAD_INITIALIZER(backendInfo);
 
 int                    nBackendDB = 0; 
-BackendDB              *backendDB = NULL;
+slap_be_head backendDB = LDAP_STAILQ_HEAD_INITIALIZER(backendDB);
 
 static int
 backend_init_controls( BackendInfo *bi )
@@ -91,26 +91,25 @@ backend_init_controls( BackendInfo *bi )
 int backend_init(void)
 {
        int rc = -1;
+       BackendInfo *bi;
 
-       if((nBackendInfo != 0) || (backendInfo != NULL)) {
+       if((nBackendInfo != 0) || !LDAP_STAILQ_EMPTY(&backendInfo)) {
                /* already initialized */
                Debug( LDAP_DEBUG_ANY,
                        "backend_init: already initialized\n", 0, 0, 0 );
                return -1;
        }
 
-       for( ;
-               slap_binfo[nBackendInfo].bi_type != NULL;
-               nBackendInfo++ )
+       for( bi=slap_binfo; bi->bi_type != NULL; bi++,nBackendInfo++ )
        {
-               assert( slap_binfo[nBackendInfo].bi_init );
+               assert( bi->bi_init );
 
-               rc = slap_binfo[nBackendInfo].bi_init( &slap_binfo[nBackendInfo] );
+               rc = bi->bi_init( bi );
 
                if(rc != 0) {
                        Debug( LDAP_DEBUG_ANY,
                                "backend_init: initialized for type \"%s\"\n",
-                               slap_binfo[nBackendInfo].bi_type, 0, 0 );
+                               bi->bi_type, 0, 0 );
                        /* destroy those we've already inited */
                        for( nBackendInfo--;
                                nBackendInfo >= 0 ;
@@ -123,10 +122,10 @@ int backend_init(void)
                        }
                        return rc;
                }
+               LDAP_STAILQ_INSERT_TAIL(&backendInfo, bi, bi_next);
        }
 
        if ( nBackendInfo > 0) {
-               backendInfo = slap_binfo;
                return 0;
        }
 
@@ -164,25 +163,9 @@ int backend_add(BackendInfo *aBackendInfo)
        (void)backend_init_controls( aBackendInfo );
 
        /* now add the backend type to the Backend Info List */
-       {
-               BackendInfo *newBackendInfo = 0;
-
-               /* if backendInfo == slap_binfo no deallocation of old backendInfo */
-               if (backendInfo == slap_binfo) {
-                       newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
-                       AC_MEMCPY(newBackendInfo, backendInfo,
-                               sizeof(BackendInfo) * nBackendInfo);
-               } else {
-                       newBackendInfo = ch_realloc(backendInfo,
-                               sizeof(BackendInfo) * (nBackendInfo + 1));
-               }
-
-               AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
-                       sizeof(BackendInfo));
-               backendInfo = newBackendInfo;
-               nBackendInfo++;
-               return 0;
-       }
+       LDAP_STAILQ_INSERT_TAIL( &backendInfo, aBackendInfo, bi_next );
+       nBackendInfo++;
+       return 0;
 }
 
 static int
@@ -255,6 +238,7 @@ int backend_startup(Backend *be)
 {
        int i;
        int rc = 0;
+       BackendInfo *bi;
 
        if( ! ( nBackendDB > 0 ) ) {
                /* no databases */
@@ -291,23 +275,25 @@ int backend_startup(Backend *be)
        }
 
        /* open each backend type */
-       for( i = 0; i < nBackendInfo; i++ ) {
-               if( backendInfo[i].bi_nDB == 0) {
+       i = -1;
+       LDAP_STAILQ_FOREACH(bi, &backendInfo, bi_next) {
+               i++;
+               if( bi->bi_nDB == 0) {
                        /* no database of this type, don't open */
                        continue;
                }
 
-               if( backendInfo[i].bi_open ) {
-                       rc = backendInfo[i].bi_open( &backendInfo[i] );
+               if( bi->bi_open ) {
+                       rc = bi->bi_open( bi );
                        if ( rc != 0 ) {
                                Debug( LDAP_DEBUG_ANY,
-                                       "backend_startup: bi_open %d failed!\n",
-                                       i, 0, 0 );
+                                       "backend_startup: bi_open %d (%s) failed!\n",
+                                       i, bi->bi_type, 0 );
                                return rc;
                        }
                }
 
-               (void)backend_init_controls( &backendInfo[i] );
+               (void)backend_init_controls( bi );
        }
 
        ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
@@ -315,26 +301,28 @@ int backend_startup(Backend *be)
        LDAP_STAILQ_INIT( &slapd_rq.run_list );
 
        /* open each backend database */
-       for( i = 0; i < nBackendDB; i++ ) {
-               if ( backendDB[i].be_suffix == NULL ) {
+       i = -1;
+       LDAP_STAILQ_FOREACH(be, &backendDB, be_next) {
+               i++;
+               if ( be->be_suffix == NULL ) {
                        Debug( LDAP_DEBUG_ANY,
                                "backend_startup: warning, database %d (%s) "
                                "has no suffix\n",
-                               i, backendDB[i].bd_info->bi_type, 0 );
+                               i, be->bd_info->bi_type, 0 );
                }
                /* append global access controls */
-               acl_append( &backendDB[i].be_acl, frontendDB->be_acl );
+               acl_append( &be->be_acl, frontendDB->be_acl );
 
-               rc = backend_startup_one( &backendDB[i] );
+               rc = backend_startup_one( be );
 
                if ( rc ) return rc;
 
 
-               if ( backendDB[i].be_syncinfo ) {
+               if ( be->be_syncinfo ) {
                        syncinfo_t *si;
 
-                       if ( !( backendDB[i].be_search && backendDB[i].be_add &&
-                               backendDB[i].be_modify && backendDB[i].be_delete )) {
+                       if ( !( be->be_search && be->be_add &&
+                               be->be_modify && be->be_delete )) {
                                Debug( LDAP_DEBUG_ANY,
                                        "backend_startup: database(%d) does not support "
                                        "operations required for syncrepl", i, 0, 0 );
@@ -342,8 +330,8 @@ int backend_startup(Backend *be)
                        }
 
                        {
-                               si = backendDB[i].be_syncinfo;
-                               si->si_be = &backendDB[i];
+                               si = be->be_syncinfo;
+                               si->si_be = be;
                                init_syncrepl( si );
                                ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                ldap_pvt_runqueue_insert( &slapd_rq,
@@ -358,12 +346,14 @@ int backend_startup(Backend *be)
 
 int backend_num( Backend *be )
 {
-       int i;
+       int i = 0;
+       BackendDB *b2;
 
        if( be == NULL ) return -1;
 
-       for( i = 0; i < nBackendDB; i++ ) {
-               if( be == &backendDB[i] ) return i;
+       LDAP_STAILQ_FOREACH( b2, &backendDB, be_next ) {
+               if( be == b2 ) return i;
+               i++;
        }
        return -1;
 }
@@ -372,6 +362,7 @@ int backend_shutdown( Backend *be )
 {
        int i;
        int rc = 0;
+       BackendInfo *bi;
 
        if( be != NULL ) {
                /* shutdown a specific backend database */
@@ -393,29 +384,27 @@ int backend_shutdown( Backend *be )
        }
 
        /* close each backend database */
-       for( i = 0; i < nBackendDB; i++ ) {
-               if ( backendDB[i].bd_info->bi_db_close ) {
-                       backendDB[i].bd_info->bi_db_close(
-                               &backendDB[i] );
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->bd_info->bi_db_close ) {
+                       be->bd_info->bi_db_close( be );
                }
 
                if(rc != 0) {
                        Debug( LDAP_DEBUG_ANY,
                                "backend_close: bi_db_close %s failed!\n",
-                               backendDB[i].be_type, 0, 0 );
+                               be->be_type, 0, 0 );
                }
        }
 
        /* close each backend type */
-       for( i = 0; i < nBackendInfo; i++ ) {
-               if( backendInfo[i].bi_nDB == 0 ) {
+       LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
+               if( bi->bi_nDB == 0 ) {
                        /* no database of this type */
                        continue;
                }
 
-               if( backendInfo[i].bi_close ) {
-                       backendInfo[i].bi_close(
-                               &backendInfo[i] );
+               if( bi->bi_close ) {
+                       bi->bi_close( bi );
                }
        }
 
@@ -436,10 +425,12 @@ int backend_destroy(void)
 {
        int i;
        BackendDB *bd;
+       BackendInfo *bi;
        struct slap_csn_entry *csne;
 
        /* destroy each backend database */
-       for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
+       while (( bd = LDAP_STAILQ_FIRST(&backendDB))) {
+               LDAP_STAILQ_REMOVE_HEAD(&backendDB, be_next);
 
                if ( bd->be_syncinfo ) {
                        syncinfo_free( bd->be_syncinfo );
@@ -472,25 +463,18 @@ int backend_destroy(void)
                        free( bd->be_rootpw.bv_val );
                }
                acl_destroy( bd->be_acl, frontendDB->be_acl );
+               free( bd );
        }
-       free( backendDB );
 
        /* destroy each backend type */
-       for( i = 0; i < nBackendInfo; i++ ) {
-               if( backendInfo[i].bi_destroy ) {
-                       backendInfo[i].bi_destroy(
-                               &backendInfo[i] );
+       LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
+               if( bi->bi_destroy ) {
+                       bi->bi_destroy( bi );
                }
        }
 
-#ifdef SLAPD_MODULES
-       if (backendInfo != slap_binfo) {
-          free(backendInfo);
-       }
-#endif /* SLAPD_MODULES */
-
        nBackendInfo = 0;
-       backendInfo = NULL;
+       LDAP_STAILQ_INIT(&backendInfo);
 
        /* destroy frontend database */
        bd = frontendDB;
@@ -517,12 +501,12 @@ int backend_destroy(void)
 
 BackendInfo* backend_info(const char *type)
 {
-       int i;
+       BackendInfo *bi;
 
        /* search for the backend type */
-       for( i = 0; i < nBackendInfo; i++ ) {
-               if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
-                       return &backendInfo[i];
+       LDAP_STAILQ_FOREACH(bi,&backendInfo,bi_next) {
+               if( strcasecmp(bi->bi_type, type) == 0 ) {
+                       return bi;
                }
        }
 
@@ -543,23 +527,9 @@ backend_db_init(
                return NULL;
        }
 
-       be = backendDB;
-
-       backendDB = (BackendDB *) ch_realloc(
-                       (char *) backendDB,
-                   (nBackendDB + 1) * sizeof(Backend) );
-
-       memset( &backendDB[nbackends], '\0', sizeof(Backend) );
-
-       /* did realloc move our table? if so, fix up dependent pointers */
-       if ( be != backendDB ) {
-               int i;
-               for ( i=0, be=backendDB; i<nbackends; i++, be++ ) {
-                       be->be_pcl_mutexp = &be->be_pcl_mutex;
-               }
-       }
-
-       be = &backends[nbackends++];
+       be = ch_calloc( 1, sizeof(Backend) );
+       nbackends++;
+       LDAP_STAILQ_INSERT_TAIL(&backendDB, be, be_next);
 
        be->bd_info = bi;
 
@@ -593,11 +563,12 @@ backend_db_init(
 void
 be_db_close( void )
 {
+       BackendDB *be;
        int     i;
 
-       for ( i = 0; i < nbackends; i++ ) {
-               if ( backends[i].bd_info->bi_db_close ) {
-                       (*backends[i].bd_info->bi_db_close)( &backends[i] );
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->bd_info->bi_db_close ) {
+                       be->bd_info->bi_db_close( be );
                }
        }
 
@@ -615,22 +586,21 @@ select_backend(
 {
        int             i, j;
        ber_len_t       len, dnlen = dn->bv_len;
-       Backend         *be = NULL;
+       Backend         *be, *b2;
 
-       for ( i = 0; i < nbackends; i++ ) {
-               if ( backends[i].be_nsuffix == NULL ) {
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->be_nsuffix == NULL ) {
                        continue;
                }
 
-               for ( j = 0; !BER_BVISNULL( &backends[i].be_nsuffix[j] ); j++ )
+               for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[j] ); j++ )
                {
-                       if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
-                               && noSubs )
+                       if ( ( SLAP_GLUE_SUBORDINATE( be ) ) && noSubs )
                        {
                                continue;
                        }
 
-                       len = backends[i].be_nsuffix[j].bv_len;
+                       len = be->be_nsuffix[j].bv_len;
 
                        if ( len > dnlen ) {
                                /* suffix is longer than DN */
@@ -647,25 +617,25 @@ select_backend(
                                continue;
                        }
 
-                       if ( strcmp( backends[i].be_nsuffix[j].bv_val,
+                       if ( strcmp( be->be_nsuffix[j].bv_val,
                                &dn->bv_val[dnlen-len] ) == 0 )
                        {
-                               if( be == NULL ) {
-                                       be = &backends[i];
+                               if( b2 == NULL ) {
+                                       b2 = be;
 
                                        if( manageDSAit && len == dnlen &&
                                                !SLAP_GLUE_SUBORDINATE( be ) ) {
                                                continue;
                                        }
                                } else {
-                                       be = &backends[i];
+                                       b2 = be;
                                }
-                               return be;
+                               return b2;
                        }
                }
        }
 
-       return be;
+       return b2;
 }
 
 int
@@ -780,15 +750,16 @@ be_entry_release_rw(
 int
 backend_unbind( Operation *op, SlapReply *rs )
 {
-       int             i;
+       int             i = 0;
+       BackendDB *be;
 
-       for ( i = 0; i < nbackends; i++ ) {
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
 #if defined( LDAP_SLAPI )
                if ( op->o_pb ) {
                        int rc;
                        if ( i == 0 ) slapi_int_pblock_set_operation( op->o_pb, op );
-                       slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)&backends[i] );
-                       rc = slapi_int_call_plugins( &backends[i],
+                       slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)be );
+                       rc = slapi_int_call_plugins( be,
                                SLAPI_PLUGIN_PRE_UNBIND_FN, (Slapi_PBlock *)op->o_pb );
                        if ( rc < 0 ) {
                                /*
@@ -803,13 +774,13 @@ backend_unbind( Operation *op, SlapReply *rs )
                }
 #endif /* defined( LDAP_SLAPI ) */
 
-               if ( backends[i].be_unbind ) {
-                       op->o_bd = &backends[i];
-                       (*backends[i].be_unbind)( op, rs );
+               if ( be->be_unbind ) {
+                       op->o_bd = be;
+                       be->be_unbind( op, rs );
                }
 
 #if defined( LDAP_SLAPI )
-               if ( op->o_pb != NULL && slapi_int_call_plugins( &backends[i],
+               if ( op->o_pb != NULL && slapi_int_call_plugins( be,
                        SLAPI_PLUGIN_POST_UNBIND_FN, (Slapi_PBlock *)op->o_pb ) < 0 )
                {
                        Debug(LDAP_DEBUG_TRACE,
@@ -817,6 +788,7 @@ backend_unbind( Operation *op, SlapReply *rs )
                                0, 0, 0);
                }
 #endif /* defined( LDAP_SLAPI ) */
+               i++;
        }
 
        return 0;
@@ -826,11 +798,11 @@ int
 backend_connection_init(
        Connection   *conn )
 {
-       int     i;
+       BackendDB *be;
 
-       for ( i = 0; i < nbackends; i++ ) {
-               if ( backends[i].be_connection_init ) {
-                       (*backends[i].be_connection_init)( &backends[i], conn);
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->be_connection_init ) {
+                       be->be_connection_init( be, conn);
                }
        }
 
@@ -841,11 +813,11 @@ int
 backend_connection_destroy(
        Connection   *conn )
 {
-       int     i;
+       BackendDB *be;
 
-       for ( i = 0; i < nbackends; i++ ) {
-               if ( backends[i].be_connection_destroy ) {
-                       (*backends[i].be_connection_destroy)( &backends[i], conn);
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->be_connection_destroy ) {
+                       be->be_connection_destroy( be, conn);
                }
        }
 
index e1b31a50c1d6f6817afd4502e376361d11c2d112..f4b82dc0be0a2a85631af89810ea3a15aa6b460c 100644 (file)
@@ -545,12 +545,10 @@ overlay_register_control( BackendDB *be, const char *oid )
        }
 
        if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) {
-               int     i;
+               BackendDB *bd;
                
                /* add to all backends... */
-               for ( i = 0; i < nBackendDB; i++ ) {
-                       BackendDB       *bd = &backendDB[i];
-                       
+               LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
                        if ( be == bd ) {
                                gotit = 1;
                        }
index b09b3afb2f3391416d8b2337f91e4f8ab28106e2..f208a5d0333c12b811251491f5087d90dac64d01 100644 (file)
@@ -893,7 +893,7 @@ config_generic(ConfigArgs *c) {
                        /* NOTE: config is always the first backend!
                         */
                        if ( !strcasecmp( c->argv[1], "config" )) {
-                               c->be = backendDB;
+                               c->be = LDAP_STAILQ_FIRST(&backendDB);
                        } else if ( !strcasecmp( c->argv[1], "frontend" )) {
                                c->be = frontendDB;
                        } else if(!(c->be = backend_db_init(c->argv[1]))) {
@@ -3166,7 +3166,7 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
                        goto ok;
                /* FALLTHRU */
        case Cft_Global:
-               ca.be = backendDB;
+               ca.be = LDAP_STAILQ_FIRST(&backendDB);
                break;
 
        case Cft_Backend:
@@ -3764,8 +3764,7 @@ config_back_db_open( BackendDB *be )
         */
        
        c.line = 0;
-       bi = backendInfo;
-       for (i=0; i<nBackendInfo; i++, bi++) {
+       LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
                if (!bi->bi_cf_table) continue;
                if (!bi->bi_private) continue;
 
@@ -3788,12 +3787,14 @@ config_back_db_open( BackendDB *be )
        }
 
        /* Create database nodes... */
-       for (i=0; i<nBackendDB; i++) {
+       i = -1;
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
                slap_overinfo *oi = NULL;
+               i++;
                if ( i == 0 ) {
                        bptr = frontendDB;
                } else {
-                       bptr = &backendDB[i];
+                       bptr = be;
                }
                if ( overlay_is_over( bptr )) {
                        oi = bptr->bd_info->bi_private;
index e1256de909a789cfc43e9371fe3980cb8a6b1bbe..141229b87483be1d596b9d086aefe51242642bff 100644 (file)
@@ -90,8 +90,7 @@ int cancel_extop( Operation *op, SlapReply *rs )
 
                o->o_cancel = SLAP_CANCEL_REQ;
 
-               for ( i = 0; i < nbackends; i++ ) {
-                       op->o_bd = &backends[i];
+               LDAP_STAILQ_FOREACH( op->o_bd, &backendDB, be_next ) {
                        if( !op->o_bd->be_cancel ) continue;
 
                        op->oq_cancel.rs_msgid = opid;
index 15d41f23495609d20be9ac8534f6a5708249a9a1..be90c5c2d32267119a3776328388ebfab63af7a9 100644 (file)
@@ -72,6 +72,12 @@ typedef struct ConfigOCs {
        char *def;
        ConfigType cft;
        ObjectClass **oc;
+#if 0
+       BI_op_add *add;         /* optional, add-specific processing */
+       BI_op_delete *del;      /* mandatory, delete implementation */
+       BI_op_modify *mod;      /* optional, mod-specific */
+       BI_op_modrdn *ren;      /* optional, modrdn... */
+#endif
 } ConfigOCs;
 
 typedef struct config_args_s {
index 13da05a95285a622f527564a209c6d1a5b6f5dab..957a45655d62a70e82f1d9413728c3d3cd6724e6 100644 (file)
@@ -40,7 +40,6 @@
 
 typedef struct gluenode {
        BackendDB *gn_be;
-       int     gn_bx;
        struct berval gn_pdn;
        int gn_async;
 } gluenode;
@@ -730,23 +729,6 @@ glue_db_destroy (
        return SLAP_CB_CONTINUE;
 }
 
-static int
-glue_db_open (
-       BackendDB *be
-)
-{
-       slap_overinst   *on = (slap_overinst *)be->bd_info;
-       glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
-       int i;
-
-       for ( i=0; i<gi->gi_nodes; i++ ) {
-               int j;
-
-               gi->gi_n[i].gn_be = backendDB + gi->gi_n[i].gn_bx;
-       }
-       return 0;
-}
-
 static int
 glue_db_close( 
        BackendDB *be
@@ -813,7 +795,7 @@ glue_db_config(
                }
                gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) +
                        gi->gi_nodes * sizeof(gluenode));
-               gi->gi_n[gi->gi_nodes].gn_bx = b2 - backendDB;
+               gi->gi_n[gi->gi_nodes].gn_be = b2;
                dnParent( &b2->be_nsuffix[0], &gi->gi_n[gi->gi_nodes].gn_pdn );
                gi->gi_n[gi->gi_nodes].gn_async = async;
                gi->gi_nodes++;
@@ -830,7 +812,6 @@ glue_init()
 
        glue.on_bi.bi_db_init = glue_db_init;
        glue.on_bi.bi_db_config = glue_db_config;
-       glue.on_bi.bi_db_open = glue_db_open;
        glue.on_bi.bi_db_close = glue_db_close;
        glue.on_bi.bi_db_destroy = glue_db_destroy;
 
index dbe4f371c6abdf5907af62938be800397170115b..057b9061e9cad1da88fe2f56d6bef42f8ec36881 100644 (file)
@@ -56,6 +56,7 @@ root_dse_info(
        struct berval nvals[2];
        int             i, j;
        char ** supportedSASLMechanisms;
+       BackendDB *be;
 
        AttributeDescription *ad_structuralObjectClass
                = slap_schema.si_ad_structuralObjectClass;
@@ -116,34 +117,34 @@ root_dse_info(
                return LDAP_OTHER;
        }
 
-       for ( i = 0; i < nbackends; i++ ) {
-               if ( backends[i].be_suffix == NULL
-                               || backends[i].be_nsuffix == NULL ) {
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( be->be_suffix == NULL
+                               || be->be_nsuffix == NULL ) {
                        /* no suffix! */
                        continue;
                }
-               if ( SLAP_MONITOR( &backends[i] )) {
-                       vals[0] = backends[i].be_suffix[0];
-                       nvals[0] = backends[i].be_nsuffix[0];
+               if ( SLAP_MONITOR( be )) {
+                       vals[0] = be->be_suffix[0];
+                       nvals[0] = be->be_nsuffix[0];
                        if( attr_merge( e, ad_monitorContext, vals, nvals ) ) {
                                return LDAP_OTHER;
                        }
                        continue;
                }
-               if ( SLAP_CONFIG( &backends[i] )) {
-                       vals[0] = backends[i].be_suffix[0];
-                       nvals[0] = backends[i].be_nsuffix[0];
+               if ( SLAP_CONFIG( be )) {
+                       vals[0] = be->be_suffix[0];
+                       nvals[0] = be->be_nsuffix[0];
                        if( attr_merge( e, ad_configContext, vals, nvals ) ) {
                                return LDAP_OTHER;
                        }
                        continue;
                }
-               if ( SLAP_GLUE_SUBORDINATE( &backends[i] ) && !SLAP_GLUE_ADVERTISE( &backends[i] ) ) {
+               if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
                        continue;
                }
-               for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
-                       vals[0] = backends[i].be_suffix[j];
-                       nvals[0] = backends[i].be_nsuffix[0];
+               for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
+                       vals[0] = be->be_suffix[j];
+                       nvals[0] = be->be_nsuffix[0];
                        if( attr_merge( e, ad_namingContexts, vals, nvals ) ) {
                                return LDAP_OTHER;
                        }
index a419a941039c4046e3ba0679714ecc672a05f88e..28b63a4c9cb0baad70c9cbc64e874e6551831c9f 100644 (file)
@@ -1389,11 +1389,13 @@ typedef struct slap_acl_state {
 
 typedef struct slap_backend_info BackendInfo;  /* per backend type */
 typedef struct slap_backend_db BackendDB;              /* per backend database */
+typedef LDAP_STAILQ_HEAD(BeI, slap_backend_info) slap_bi_head;
+typedef LDAP_STAILQ_HEAD(BeDB, slap_backend_db) slap_be_head;
 
 LDAP_SLAPD_V (int) nBackendInfo;
 LDAP_SLAPD_V (int) nBackendDB;
-LDAP_SLAPD_V (BackendInfo *) backendInfo;
-LDAP_SLAPD_V (BackendDB *) backendDB;
+LDAP_SLAPD_V (slap_bi_head) backendInfo;
+LDAP_SLAPD_V (slap_be_head) backendDB;
 LDAP_SLAPD_V (BackendDB *) frontendDB;
 
 LDAP_SLAPD_V (int) slapMode;   
@@ -1736,6 +1738,7 @@ struct slap_backend_db {
        struct ConfigTable *be_cf_table;
 
        void    *be_private;    /* anything the backend database needs     */
+       LDAP_STAILQ_ENTRY(slap_backend_db) be_next;
 };
 
 struct slap_conn;
@@ -2068,6 +2071,7 @@ struct slap_backend_info {
        unsigned int bi_nDB;    /* number of databases of this type */
        struct ConfigTable *bi_cf_table;
        void    *bi_private;    /* anything the backend type needs */
+       LDAP_STAILQ_ENTRY(slap_backend_info) bi_next ;
 };
 
 #define c_authtype     c_authz.sai_method
@@ -2921,11 +2925,10 @@ struct zone_heap {
 #endif
 
 #define SLAP_BACKEND_INIT_MODULE(b) \
+       static BackendInfo bi;  \
        int \
        init_module( int argc, char *argv[] ) \
        { \
-               BackendInfo bi; \
-               memset( &bi, '\0', sizeof( bi ) ); \
                bi.bi_type = #b ; \
                bi.bi_init = b ## _back_initialize; \
                backend_add( &bi ); \
index 4a0c55a600dd3c9527f81981c0179877251ea9c1..ab0048db057d5503371b599a2d00fff29ec5bdae 100644 (file)
@@ -446,21 +446,24 @@ slap_tool_init(
                        fprintf( stderr, "No available databases\n" );
                        exit( EXIT_FAILURE );
                }
+               LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+                       dbnum++;
+                       if ( dbnum < 1 ) continue;
                
-               be = &backends[dbnum=1];
+                       if ( SLAP_MONITOR(be))
+                               continue;
+
                /* If just doing the first by default and it is a
                 * glue subordinate, find the master.
                 */
-               while (SLAP_GLUE_SUBORDINATE(be) || SLAP_MONITOR(be)) {
-                       if (SLAP_GLUE_SUBORDINATE(be)) {
+                       if ( SLAP_GLUE_SUBORDINATE(be) ) {
                                nosubordinates = 1;
+                               continue;
                        }
-                       be++;
-                       dbnum++;
+                       break;
                }
 
-
-               if ( dbnum >= nbackends ) {
+               if ( !be ) {
                        fprintf( stderr, "Available database(s) "
                                        "do not allow %s\n", progname );
                        exit( EXIT_FAILURE );
@@ -482,7 +485,10 @@ slap_tool_init(
                exit( EXIT_FAILURE );
 
        } else {
-               be = &backends[dbnum];
+               LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+                       if ( dbnum == 0 ) break;
+                       dbnum--;
+               }
        }
 
 startup:;