]> git.sur5r.net Git - openldap/commitdiff
fix multiple response messages; add overall sleep time
authorPierangelo Masarati <ando@openldap.org>
Thu, 30 Mar 2006 23:49:51 +0000 (23:49 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 30 Mar 2006 23:49:51 +0000 (23:49 +0000)
doc/man/man5/slapo-retcode.5
servers/slapd/overlays/retcode.c

index 2a0fbf4bb97618db108a1106c3c43aba803acc70..1ee77d919c5cb5355933fb40516b4b403721a447 100644 (file)
@@ -73,6 +73,12 @@ response code.
 .B retcode\-indir
 Enables exploitation of in-directory stored errAbsObject.
 May result in a lot of unnecessary overhead.
+.TP
+.B retcode\-sleep [-]<n>
+Defines a sleep time in seconds that is spent before actually handling
+any operation.
+If negative, a random time between 0 and the absolute value of the argument
+is used.
 
 .SH SCHEMA
 The
index cad6b86bed26b3a566e196fd007d368d17800d70..8b09f733613228d0a4047a771ba4bd4003fe8415 100644 (file)
@@ -77,6 +77,8 @@ typedef struct retcode_t {
        struct berval           rd_pdn;
        struct berval           rd_npdn;
 
+       int                     rd_sleep;
+
        retcode_item_t          *rd_item;
 
        unsigned                rd_flags;
@@ -202,7 +204,6 @@ retcode_op_internal( Operation *op, SlapReply *rs )
        slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
 
        Operation       op2 = *op;
-       SlapReply       rs2 = { 0 };
        BackendDB       db = *op->o_bd;
        slap_callback   sc = { 0 };
        retcode_cb_t    rdc;
@@ -236,7 +237,8 @@ retcode_op_internal( Operation *op, SlapReply *rs )
        sc.sc_private = &rdc;
        op2.o_callback = &sc;
 
-       rc = op2.o_bd->be_search( &op2, &rs2 );
+       rc = op2.o_bd->be_search( &op2, rs );
+       op->o_abandon = op2.o_abandon;
 
        filter_free_x( &op2, op2.ors_filter );
        ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx );
@@ -259,6 +261,14 @@ retcode_op_func( Operation *op, SlapReply *rs )
 
        slap_callback           *cb = NULL;
 
+       /* sleep as required */
+       if ( rd->rd_sleep < 0 ) {
+               sleep( rand() % ( - rd->rd_sleep ) );
+
+       } else if ( rd->rd_sleep > 0 ) {
+               sleep( rd->rd_sleep );
+       }
+
        if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) {
                if ( RETCODE_INDIR( rd ) ) {
                        switch ( op->o_tag ) {
@@ -275,10 +285,18 @@ retcode_op_func( Operation *op, SlapReply *rs )
                        case LDAP_REQ_SEARCH:
                                if ( op->ors_scope == LDAP_SCOPE_BASE ) {
                                        rs->sr_err = retcode_op_internal( op, rs );
-                                       if ( rs->sr_err == SLAP_CB_CONTINUE ) {
+                                       switch ( rs->sr_err ) {
+                                       case SLAP_CB_CONTINUE:
+                                               if ( rs->sr_nentries == 0 ) {
+                                                       break;
+                                               }
                                                rs->sr_err = LDAP_SUCCESS;
+                                               /* fallthru */
+
+                                       default:
+                                               send_ldap_result( op, rs );
+                                               break;
                                        }
-                                       send_ldap_result( op, rs );
                                        return rs->sr_err;
                                }
                                break;
@@ -874,6 +892,31 @@ retcode_db_config(
        } else if ( strcasecmp( argv0, "indir" ) == 0 ) {
                rd->rd_flags |= RETCODE_FINDIR;
 
+       } else if ( strcasecmp( argv0, "sleep" ) == 0 ) {
+               switch ( argc ) {
+               case 1:
+                       fprintf( stderr, "%s: line %d: retcode: "
+                               "\"retcode-sleep <time>\": missing <time>\n",
+                               fname, lineno );
+                       return 1;
+
+               case 2:
+                       break;
+
+               default:
+                       fprintf( stderr, "%s: line %d: retcode: "
+                               "\"retcode-sleep <time>\": extra cruft after <time>\n",
+                               fname, lineno );
+                       return 1;
+               }
+
+               if ( lutil_atoi( &rd->rd_sleep, argv[ 1 ] ) != 0 ) {
+                       fprintf( stderr, "%s: line %d: retcode: "
+                               "\"retcode-sleep <time>\": unable to parse <time>\n",
+                               fname, lineno );
+                       return 1;
+               }
+
        } else {
                return SLAP_CONF_UNKNOWN;
        }