-#ifdef LDAP_SLAPI
-static AttributeName *charray2anlist( Operation *op, char **attrs )
-{
- AttributeName *an;
- int i;
-
- if ( attrs != NULL ) {
- for ( i = 0; attrs[i] != NULL; i++ )
- ;
- an = (AttributeName *)op->o_tmpalloc( (i + 1) * sizeof(AttributeName), op->o_tmpmemctx );
- for ( i = 0; attrs[i] != NULL; i++ ) {
- const char *dummy;
-
- an[i].an_name.bv_val = attrs[i];
- an[i].an_name.bv_len = strlen( attrs[i] );
- an[i].an_oc = NULL;
- an[i].an_oc_exclude = 0;
- slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
- }
- } else {
- an = NULL;
- }
-
- return an;
-}
-
-/*
- * Call pre-response plugins. To avoid infinite recursion plugins
- * should just set SLAPI_RESULT_CODE rather than sending a
- * result if they wish to change the result. Similarly, pre-entry
- * plugins can either abort sending the entry or change the list
- * of sent attributes, but they can't call send_search_entry().
- */
-
-static int call_pre_entry_plugins( Operation *op, SlapReply *rs, int *pAttributesOnly )
-{
- int rc;
- char **attrs = NULL;
- char **filteredAttributes = NULL;
- Slapi_PBlock *pb;
-
- if ( op->o_callback != NULL || op->o_pb == NULL ) {
- return 0;
- }
-
- /*
- * A new parameter block is allocated to avoid trampling on the
- * operation SLAPI state.
- */
- pb = slapi_pblock_new();
-
- slapi_int_pblock_set_operation( pb, op );
- slapi_pblock_set( pb, SLAPI_RESCONTROLS, (void *)rs->sr_ctrls );
- attrs = anlist2charray_x( op->ors_attrs, 0, op->o_tmpmemctx );
- slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS, (void *)attrs );
- slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)*pAttributesOnly );
- slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, (void *)rs->sr_entry );
-
- rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_ENTRY_FN, pb );
- if ( rc < 0 ) {
- slapi_pblock_destroy( pb );
- return rc;
- }
-
- slapi_pblock_get( pb, SLAPI_RESCONTROLS, (void **)&rs->sr_ctrls );
- slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, (void **)&filteredAttributes );
- slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, (void **)pAttributesOnly );
- slapi_pblock_get( pb, SLAPI_SEARCH_RESULT_ENTRY, (void **)&rs->sr_entry );
-
- if ( filteredAttributes != attrs ) {
- /*
- * Support for filtering attributes; useful for implementing
- * replication providers
- */
- rs->sr_attrs = charray2anlist( op, filteredAttributes );
- slapi_ch_free( (void **)&filteredAttributes );
- }
-
- slapi_pblock_set( pb, SLAPI_RESCONTROLS, NULL );
- slapi_pblock_destroy( pb );
-
- return rc;
-}
-
-static int call_pre_result_plugins( Operation *op, SlapReply *rs )
-{
- int rc;
-
- if ( op->o_callback != NULL || op->o_pb == NULL ) {
- return 0;
- }
-
- slapi_pblock_set( op->o_pb, SLAPI_RESCONTROLS, (void *)rs->sr_ctrls );
- slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
- slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
- slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched );
-
- rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN, op->o_pb );
- if ( rc < 0 ) {
- return rc;
- }
-
- slapi_pblock_get( op->o_pb, SLAPI_RESCONTROLS, (void **)&rs->sr_ctrls );
- slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void **)&rs->sr_err );
- slapi_pblock_get( op->o_pb, SLAPI_RESULT_TEXT, (void **)&rs->sr_text );
- slapi_pblock_get( op->o_pb, SLAPI_RESULT_MATCHED, (void **)&rs->sr_matched );
-
- slapi_pblock_set( op->o_pb, SLAPI_RESCONTROLS, NULL );
-
- return rc;
-}
-
-static int call_pre_referral_plugins( Operation *op, SlapReply *rs )
-{
- int rc;
- Slapi_PBlock *pb;
-
- if ( op->o_callback != NULL || op->o_pb == NULL ) {
- return 0;
- }
-
- /*
- * A new parameter block is allocated to avoid trampling on the
- * operation SLAPI state.
- */
- pb = slapi_pblock_new();
-
- slapi_int_pblock_set_operation( pb, op );
- slapi_pblock_set( pb, SLAPI_RESCONTROLS, (void *)rs->sr_ctrls );
- slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, (void *)rs->sr_entry );
-
- rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_REFERRAL_FN, pb );
- if ( rc < 0 ) {
- return rc;
- }
-
- slapi_pblock_get( pb, SLAPI_RESCONTROLS, (void **)&rs->sr_ctrls );
- slapi_pblock_get( pb, SLAPI_SEARCH_RESULT_ENTRY, (void **)&rs->sr_entry );
-
- slapi_pblock_set( pb, SLAPI_RESCONTROLS, NULL );
- slapi_pblock_destroy( pb );
-
- return rc;
-}
-#endif /* LDAP_SLAPI */