/*********************************************************************
* Function Name: slapi_int_register_plugin
*
- * Description: insert the slapi_pblock structure to the end of the plugin
+ * Description: insert the slapi_pblock structure to a given position the end of the plugin
* list
*
* Input: a pointer to a plugin slapi_pblock structure to be added to
* Messages: None
*********************************************************************/
int
-slapi_int_register_plugin(
+slapi_int_register_plugin_index(
Backend *be,
- Slapi_PBlock *pPB )
+ Slapi_PBlock *pPB,
+ int index )
{
Slapi_PBlock *pTmpPB;
Slapi_PBlock *pSavePB;
- int rc = LDAP_SUCCESS;
+ int pos = 0, rc = LDAP_SUCCESS;
assert( be != NULL );
pTmpPB = SLAPI_BACKEND_PBLOCK( be );
- if ( pTmpPB == NULL ) {
+ if ( pTmpPB == NULL || index == 0 ) {
SLAPI_BACKEND_PBLOCK( be ) = pPB;
} else {
- while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) {
+ while ( pTmpPB != NULL && rc == LDAP_SUCCESS &&
+ ( index < 0 || pos++ < index ) ) {
pSavePB = pTmpPB;
rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB );
}
rc = slapi_pblock_set( pSavePB, SLAPI_IBM_PBLOCK, (void *)pPB );
}
}
+
+ if ( index >= 0 && rc == LDAP_SUCCESS ) {
+ rc = slapi_pblock_set( pPB, SLAPI_IBM_PBLOCK, (void *)pTmpPB );
+ }
return ( rc != LDAP_SUCCESS ) ? LDAP_OTHER : LDAP_SUCCESS;
}
-
+
+int
+slapi_int_register_plugin(
+ Backend *be,
+ Slapi_PBlock *pPB )
+{
+ return slapi_int_register_plugin_index( be, pPB, -1 );
+}
+
/*********************************************************************
* Function Name: slapi_int_get_plugins
*
const char *fname,
int lineno,
int argc,
- char **argv )
+ char **argv,
+ int index )
{
int iType = -1;
int numPluginArgc = 0;
}
}
- rc = slapi_int_register_plugin( be, pPlugin );
+ rc = slapi_int_register_plugin_index( be, pPlugin, index );
if ( rc != LDAP_SUCCESS ) {
if ( iType == SLAPI_PLUGIN_EXTENDEDOP ) {
slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin );
return 0;
}
+int
+slapi_int_unregister_plugin(
+ Backend *be,
+ Slapi_PBlock *pPlugin,
+ Slapi_PBlock *pPrev
+)
+{
+ int type;
+
+ assert( pPlugin != NULL );
+
+ slapi_pblock_get( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
+ if ( type == SLAPI_PLUGIN_EXTENDEDOP ) {
+ slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin );
+ }
+
+ if ( pPrev != NULL ) {
+ Slapi_PBlock *pNext = NULL;
+
+ slapi_pblock_get( pPlugin, SLAPI_IBM_PBLOCK, &pNext );
+ slapi_pblock_set( pPrev, SLAPI_IBM_PBLOCK, &pNext );
+ }
+ slapi_pblock_destroy( pPlugin );
+
+ return LDAP_SUCCESS;
+}
+
+int
+slapi_int_unregister_plugins(
+ Backend *be,
+ int index
+)
+{
+ Slapi_PBlock *pTmpPB = NULL;
+ Slapi_PBlock *pSavePB = NULL;
+ int rc = LDAP_SUCCESS;
+
+ pTmpPB = SLAPI_BACKEND_PBLOCK( be );
+ if ( pTmpPB == NULL ) {
+ return ( index < 0 ) ? LDAP_SUCCESS : LDAP_OTHER;
+ }
+
+ if ( index < 0 ) {
+ /* All plugins must go */
+ while ( pTmpPB != NULL && rc == LDAP_SUCCESS ) {
+ pSavePB = pTmpPB;
+ rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB );
+ if ( pSavePB != NULL ) {
+ slapi_int_unregister_plugin( be, pSavePB, NULL );
+ }
+ }
+ } else if ( index == 0 ) {
+ slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pSavePB );
+ SLAPI_BACKEND_PBLOCK( be ) = pSavePB;
+ slapi_int_unregister_plugin( be, pTmpPB, NULL );
+ } else {
+ int pos = -1;
+ while ( pTmpPB != NULL && rc == LDAP_SUCCESS && ++pos < index ) {
+ pSavePB = pTmpPB;
+ rc = slapi_pblock_get( pTmpPB, SLAPI_IBM_PBLOCK, &pTmpPB );
+ }
+ if ( pos == index ) {
+ slapi_int_unregister_plugin( be, pTmpPB, pSavePB );
+ }
+ }
+ return rc;
+}
+
void
slapi_int_plugin_unparse(
Backend *be,
/* plugin.c */
LDAP_SLAPI_F (int) slapi_int_register_plugin LDAP_P((Backend *be, Slapi_PBlock *pPB));
+LDAP_SLAPI_F (int) slapi_int_register_plugin_index LDAP_P((Backend *be, Slapi_PBlock *pPB, int index));
LDAP_SLAPI_F (int) slapi_int_call_plugins LDAP_P((Backend *be, int funcType, Slapi_PBlock * pPB));
LDAP_SLAPI_F (int) slapi_int_get_plugins LDAP_P((Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs));
LDAP_SLAPI_F (int) slapi_int_register_extop LDAP_P((Backend *pBE, ExtendedOp **opList, Slapi_PBlock *pPB));
LDAP_SLAPI_F (int) slapi_int_get_extop_plugin LDAP_P((struct berval *reqoid, SLAPI_FUNC *pFuncAddr ));
LDAP_SLAPI_F (struct berval *) slapi_int_get_supported_extop LDAP_P(( int ));
+LDAP_SLAPI_F (int) slapi_int_unregister_plugins LDAP_P((Backend *be, int index));
LDAP_SLAPI_F (int) slapi_int_read_config LDAP_P((Backend *be, const char *fname, int lineno,
- int argc, char **argv ));
+ int argc, char **argv, int index ));
LDAP_SLAPI_F (void) slapi_int_plugin_unparse LDAP_P((Backend *be, BerVarray *out ));
LDAP_SLAPI_F (int) slapi_int_initialize LDAP_P((void));