/********************************************************************* * Function Name: slapi_int_register_plugin * * Description: insert the slapi_pblock structure to the end of the plugin * list * * Input: a pointer to a plugin slapi_pblock structure to be added to * the list * * Output: none * * Return Values: LDAP_SUCCESS - successfully inserted. * LDAP_LOCAL_ERROR. * * Messages: None *********************************************************************/ int slapi_int_register_plugin( Backend *be, Slapi_PBlock *pPB ) { Slapi_PBlock *pTmpPB; Slapi_PBlock *pSavePB; int rc = LDAP_SUCCESS; assert( be != NULL ); pTmpPB = SLAPI_BACKEND_PBLOCK( be ); if ( pTmpPB == NULL ) { SLAPI_BACKEND_PBLOCK( be ) = pPB; } else { while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) { pSavePB = pTmpPB; rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB ); } if ( rc == LDAP_SUCCESS ) { rc = slapi_pblock_set( pSavePB, SLAPI_IBM_PBLOCK, (void *)pPB ); } } return ( rc != LDAP_SUCCESS ) ? LDAP_OTHER : LDAP_SUCCESS; }
/* * OpenLDAP extension */ int slapi_int_pblock_get_first( Backend *be, Slapi_PBlock **pb ) { assert( pb != NULL ); *pb = SLAPI_BACKEND_PBLOCK( be ); return (*pb == NULL ? LDAP_OTHER : LDAP_SUCCESS); }
void slapi_int_plugin_unparse( Backend *be, BerVarray *out ) { Slapi_PBlock *pp; int i, j; char **argv, ibuf[32], *ptr; struct berval idx, bv; *out = NULL; idx.bv_val = ibuf; i = 0; for ( pp = SLAPI_BACKEND_PBLOCK( be ); pp != NULL; slapi_pblock_get( pp, SLAPI_IBM_PBLOCK, &pp ) ) { slapi_pblock_get( pp, SLAPI_X_CONFIG_ARGV, &argv ); if ( argv == NULL ) /* could be dynamic plugin */ continue; idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), "{%d}", i ); if ( idx.bv_len >= sizeof( ibuf ) ) { /* FIXME: just truncating by now */ idx.bv_len = sizeof( ibuf ) - 1; } bv.bv_len = idx.bv_len; for (j=1; argv[j]; j++) { bv.bv_len += strlen(argv[j]); if ( j ) bv.bv_len++; } bv.bv_val = ch_malloc( bv.bv_len + 1 ); ptr = lutil_strcopy( bv.bv_val, ibuf ); for (j=1; argv[j]; j++) { if ( j ) *ptr++ = ' '; ptr = lutil_strcopy( ptr, argv[j] ); } ber_bvarray_add( out, &bv ); } }
/********************************************************************* * Function Name: slapi_int_get_plugins * * Description: get the desired type of function pointers defined * in all the plugins * * Input: the type of the functions to get, such as pre-operation,etc. * * Output: none * * Return Values: this routine returns a pointer to an array of function * pointers containing backend-specific plugin functions * followed by global plugin functions * * Messages: None *********************************************************************/ int slapi_int_get_plugins( Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs ) { Slapi_PBlock *pCurrentPB; SLAPI_FUNC FuncPtr; SLAPI_FUNC *pTmpFuncPtr; int numPB = 0; int rc = LDAP_SUCCESS; assert( ppFuncPtrs != NULL ); if ( be == NULL ) { goto done; } pCurrentPB = SLAPI_BACKEND_PBLOCK( be ); while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) { rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr ); if ( rc == LDAP_SUCCESS ) { if ( FuncPtr != NULL ) { numPB++; } rc = slapi_pblock_get( pCurrentPB, SLAPI_IBM_PBLOCK, &pCurrentPB ); } } if ( numPB == 0 ) { *ppFuncPtrs = NULL; rc = LDAP_SUCCESS; goto done; } /* * Now, build the function pointer array of backend-specific * plugins followed by global plugins. */ *ppFuncPtrs = pTmpFuncPtr = (SLAPI_FUNC *)ch_malloc( ( numPB + 1 ) * sizeof(SLAPI_FUNC) ); if ( ppFuncPtrs == NULL ) { rc = LDAP_NO_MEMORY; goto done; } pCurrentPB = SLAPI_BACKEND_PBLOCK( be ); while ( pCurrentPB != NULL && rc == LDAP_SUCCESS ) { rc = slapi_pblock_get( pCurrentPB, functype, &FuncPtr ); if ( rc == LDAP_SUCCESS ) { if ( FuncPtr != NULL ) { *pTmpFuncPtr = FuncPtr; pTmpFuncPtr++; } rc = slapi_pblock_get( pCurrentPB, SLAPI_IBM_PBLOCK, &pCurrentPB ); } } *pTmpFuncPtr = NULL; done: if ( rc != LDAP_SUCCESS && *ppFuncPtrs != NULL ) { ch_free( *ppFuncPtrs ); *ppFuncPtrs = NULL; } return rc; }