[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Move SLAPI in an overlay...



[moving to -devel, just in case...]

>
> Hmm, I'm not sure whether I've really got the hang of overlays yet. Does
> the following look about right?

Not that much, see below.

>
> Also, I'm not sure whether it will be possible to move the SLAPI code
> out of result.c, because of the way computed attributes work (they are
> not stored in the entry) -- but I figure that getting as much of SLAPI
> out of the frontend as possible is a good start.

I bet we can; maybe we need to hijack quite a bit
rs->sr_operational_attrs, which is exactly intended to append generated
attributes (we need to make sure that, despite the name, it doesn't imply
attributes have to be operational; I think the change would be of general
usefulness anyway.


static int
slapi_op_search( Operation *op, SlapReply *rs )
{
        int             manageDSAit = get_manageDSAit( op );
        char            **attrs;
        void            *private;
        slap_overinst   *on;
        Slapi_PBlock    *pb = op->o_pb;

        /* FIXME: I guess we shouldn't get here if op->o_pb == NULL;
         * if my understanding is correct, I'd rather put an assert here */
        if ( op->o_pb == NULL ) {
                return SLAP_CB_CONTINUE;
        }

        attrs = anlist2charray_x( op->ors_attrs, 0, op->o_tmpmemctx );

        slapi_int_pblock_set_operation( pb, op );
        slapi_pblock_set( pb, SLAPI_SEARCH_TARGET,
                (void *)op->o_req_dn.bv_val );
        slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE,
                (void*)op->ors_scope );
        slapi_pblock_set( pb, SLAPI_SEARCH_DEREF,
                (void *)op->ors_deref );
        slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT,
                (void *)op->ors_slimit );
        slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT,
                (void *)op->ors_tlimit );
        slapi_pblock_set( pb, SLAPI_SEARCH_FILTER,
                (void *)op->ors_filter );
        slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER,
                (void *)op->ors_filterstr.bv_val );
        slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS,
                (void *)attrs );
        slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY,
                (void *)op->ors_attrsonly );
        slapi_pblock_set( pb, SLAPI_MANAGEDSAIT,
                (void *)manageDSAit );

        on = (slap_overinst *)op->o_bd->bd_info;
        op->o_bd->bd_info = (BackendInfo *)on->on_info;

        /* FIXME: do you need this?  also, "private" is a reserved C++
         * word, some (stupid) editors/compilers may not like it */
        private = op->o_bd->be_private;

        rs->sr_err = slapi_over_call_plugins( op,
                SLAPI_PLUGIN_PRE_SEARCH_FN, pb );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                goto cleanup;
        }

        rs->sr_err = slapi_over_call_search_rewrite_plugins( op, pb );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                send_ldap_result( op, rs );
                goto cleanup;
        }

        op->o_bd->bd_info = (BackendInfo *)on;

        return SLAP_CB_CONTINUE;

cleanup:
        if ( attrs != NULL ) {
                op->o_tmpfree( attrs, op->o_tmpmemctx );
        }

        return rs->sr_err;
}

static int
slapi_response( Operation *op, SlapReply *rs )
{
        slap_overinst   *on;
        Slapi_PBlock    *pb = op->o_pb;

        /* NOTE: see comments above about op->o_pb ... */

        switch( rs->sr_type ) {
        case REP_RESULT:
                if ( op->o_tag == LDAP_REQ_SEARCH ) {
                        on = (slap_overinst *)op->o_bd->bd_info;
                        op->o_bd->bd_info =
                                (BackendInfo *)on->on_info;

                        slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
                                (void *)rs->sr_err );
                        slapi_over_call_plugins( op,
                                SLAPI_PLUGIN_POST_SEARCH_FN, pb );

                        op->o_bd->bd_info = (BackendInfo *)on;
                }
                break;

                /* add more... */
        }

        return SLAP_CB_CONTINUE;
}

static int
slapi_cleanup( Operation *op, SlapReply *rs )
{
        slap_overinst   *on;
        Slapi_PBlock    *pb = op->o_pb;

        /* NOTE: see comments above about op->o_pb ... */

        switch( rs->sr_type ) {
        case REP_RESULT:
                if ( op->o_tag == LDAP_REQ_SEARCH ) {
                        char            **attrs;

                        slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS,
                                (void **)&attrs );

                        if ( attrs != NULL )
                                op->o_tmpfree( attrs, op->o_tmpmemctx );
                        }
                }
                break;

                /* add more... */
        }

        return SLAP_CB_CONTINUE;
}

That is: split pre (into slapi_op_search), post (into slapi_response) and,
if required, cleanup (into slapi_cleanup).  Make sure you don't leak
stuff.

Ciao, p.

-- 
Pierangelo Masarati
mailto:pierangelo.masarati@sys-net.it


    SysNet - via Dossi,8 27100 Pavia Tel: +390382573859 Fax: +390382476497