+
+#ifdef LDAP_SLAPI
+
+static char **anlist2charray( AttributeName *an )
+{
+ char **attrs;
+ int i;
+
+ if ( an != NULL ) {
+ for ( i = 0; an[i].an_name.bv_val != NULL; i++ )
+ ;
+ attrs = (char **)ch_malloc( (i + 1) * sizeof(char *) );
+ for ( i = 0; an[i].an_name.bv_val != NULL; i++ ) {
+ attrs[i] = an[i].an_name.bv_val;
+ }
+ attrs[i] = NULL;
+ } else {
+ attrs = NULL;
+ }
+
+ return attrs;
+}
+
+static Slapi_PBlock *initSearchPlugin( Backend *be, Connection *conn, Operation *op,
+ struct berval *base, int scope, int deref, int sizelimit,
+ int timelimit, Filter *filter, struct berval *fstr,
+ char **attrs, int attrsonly, int managedsait )
+{
+ Slapi_PBlock *pb;
+
+ pb = op->o_pb;
+
+ slapi_x_backend_set_pb( pb, be );
+ slapi_x_connection_set_pb( pb, conn );
+ slapi_x_operation_set_pb( pb, op );
+ slapi_pblock_set( pb, SLAPI_SEARCH_TARGET, (void *)base->bv_val );
+ slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, (void *)scope );
+ slapi_pblock_set( pb, SLAPI_SEARCH_DEREF, (void *)deref );
+ slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)sizelimit );
+ slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT, (void *)timelimit );
+ slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, (void *)filter );
+ slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)fstr->bv_val );
+ slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS, (void *)attrs );
+ slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
+ slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)managedsait );
+
+ return pb;
+}
+
+static int doPreSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
+{
+ int rc;
+
+ rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_SEARCH_FN, pb );
+ if ( rc != 0 ) {
+ /*
+ * A preoperation plugin failure will abort the
+ * entire operation.
+ */
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, INFO, "doPreSearchPluginFNs: search preoperation plugin "
+ "returned %d\n", rc, 0, 0 );
+#else
+ Debug(LDAP_DEBUG_TRACE, "doPreSearchPluginFNs: search preoperation plugin "
+ "returned %d.\n", rc, 0, 0);
+#endif
+ if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0)
+ rc = LDAP_OTHER;
+ } else {
+ rc = LDAP_SUCCESS;
+ }
+
+ return rc;
+}
+
+static int doSearchRewriteFNs( Backend *be, Slapi_PBlock *pb, Filter **filter, struct berval *fstr )
+{
+ if ( doPluginFNs( be, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb ) == 0 ) {
+ /*
+ * The plugin can set the SLAPI_SEARCH_FILTER.
+ * SLAPI_SEARCH_STRFILER is not normative.
+ */
+ slapi_pblock_get( pb, SLAPI_SEARCH_FILTER, (void *)filter);
+ ch_free( fstr->bv_val );
+ filter2bv( *filter, fstr );
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ARGS,
+ "doSearchRewriteFNs: after compute_rewrite_search filter: %s\n",
+ fstr->bv_len ? fstr->bv_val : "empty", 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ARGS, " after compute_rewrite_search filter: %s\n",
+ fstr->bv_len ? fstr->bv_val : "empty", 0, 0 );
+#endif
+ }
+
+ return LDAP_SUCCESS;
+}
+
+static int doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
+{
+ if ( doPluginFNs( be, SLAPI_PLUGIN_POST_SEARCH_FN, pb ) != 0 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, INFO, "doPostSearchPluginFNs: search postoperation plugins "
+ "failed\n", 0, 0, 0 );
+#else
+ Debug(LDAP_DEBUG_TRACE, "doPostSearchPluginFNs: search postoperation plugins "
+ "failed.\n", 0, 0, 0);
+#endif
+ }
+
+ return LDAP_SUCCESS;
+}
+
+void dummy(void)
+{
+ /*
+ * XXX slapi_search_internal() was no getting pulled
+ * in; all manner of linker flags failed to link it.
+ * FIXME
+ */
+ slapi_search_internal( NULL, 0, NULL, NULL, NULL, 0 );
+}
+#endif /* LDAP_SLAPI */
+